<!--
 * @Description: 维修开单
 * @Autor: 何兴家
 * @Date: 2020-10-27 15:24:14
 * @LastEditors: 马毅
 * @LastEditTime: 2021-12-22 15:58:17
-->
<template>
  <div class="mainWrap">
    <!-- ---------------------顶部按钮--------------------- -->
    <ButtonArea :style="{ paddingTop: '15px' }">
      <el-button type="primary" :disabled="topBtnDisabledStatus.createBtn" @click="handleCreateNewOrderBtnClick">新增</el-button>
      <el-button type="primary" :disabled="topBtnDisabledStatus.editBtn" @click="handleEditBtnClick">编辑</el-button>
      <!-- <el-button type="primary" :disabled="topBtnDisabledStatus.printBtn">打印工单</el-button> -->
      <printRepairOrder :roNo="roNoFormValue" :disabled="topBtnDisabledStatus.printBtn" @printSuccess="handleOrderPirntSuccess" />
      <AjaxButton type="primary" :disabled="topBtnDisabledStatus.saveBtn" :click="handleSaveRepairOrder">保存</AjaxButton>
      <el-button type="primary" :disabled="topBtnDisabledStatus.cancenBtn" @click="handleCancelBtnClick">取消</el-button>
      <el-button type="primary" :disabled="topBtnDisabledStatus.cancellationBtn" @click="handleDiscardRepairOrderClick">作废</el-button>
      <!-- <el-button type="primary" :disabled="topBtnDisabledStatus.confirmBtn">工单确认</el-button>
      <el-button type="primary" :disabled="topBtnDisabledStatus.confirmBtn">诊断仪读取</el-button> -->
    </ButtonArea>

    <!-- ---------------------左侧信息区域--------------------- -->
    <div class="left" v-loading="pageIsLoading">
      <FormPanel ref="orderBaseInfoForm" :list="orderBaseInfoFormList" :cols="1" :labelWidth="90" :isSubmitBtn="false"></FormPanel>
      <el-tabs v-model="activePriceInfoTab" tab-position="top">
        <el-tab-pane label="自费估价信息" name="自费估价信息">
          <FormPanel ref="selfPayPriceForm" :list="selfPayPriceFormList" :cols="1" :labelWidth="90" :isSubmitBtn="false" formType="show"></FormPanel>
        </el-tab-pane>
        <el-tab-pane label="索赔估价信息" name="索赔估价信息">
          <FormPanel ref="claimPayPriceForm" :list="claimPayPriceFormList" :cols="1" :labelWidth="110" :isSubmitBtn="false" formType="show"></FormPanel>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- ---------------------右侧信息区域--------------------- -->
    <div class="right" v-loading="pageIsLoading">
      <!-- 工单主信息 -->
      <el-tabs v-model="activeMainOrderInfoTab" tab-position="top">
        <el-tab-pane label="车主车辆信息" name="车主车辆信息">
          <FormPanel ref="ownerInfoForm" :list="ownerInfoFormList" :labelWidth="100" :isSubmitBtn="false"></FormPanel>
        </el-tab-pane>
        <el-tab-pane label="维修信息" name="维修信息" style="min-height: 220px">
          <FormPanel ref="repairInfoForm" :list="repairInfoFormList" :labelWidth="100" :isSubmitBtn="false"></FormPanel>
        </el-tab-pane>
        <el-tab-pane label="工单信息" name="工单信息" style="min-height: 220px">
          <FormPanel ref="mainOrderInfoForm" :list="mainOrderInfoFormList" :labelWidth="100" :isSubmitBtn="false"></FormPanel>
        </el-tab-pane>
        <el-tab-pane label="环检照片" name="环检照片" v-if="showUploadImg">
          <div style="height: 220px; overflow-y: auto; overflow-x: hidden">
            <uploadRingCheckImgs ref="uploadRingCheckImgs" :defaultData="defaultRingCheckPhotoObj" :formDisabled="uploadImgFormDisabled" />
          </div>
        </el-tab-pane>
      </el-tabs>

      <!-- 备注单独存放 -->
      <FormPanel ref="orderRemarkForm" :list="orderRemarkFormList" :labelWidth="100" :isSubmitBtn="false"></FormPanel>

      <!-- 项目配件信息 -->
      <ButtonArea :style="{ paddingTop: '10px' }">
        <!-- <el-button type="primary" :disabled="btnDisabledWithPageType || isFirstMaintenanceChecked" @click="handleActivityBtnClick">服务活动</el-button> 无服务活动去除 hxj 2020-12-28 -->
        <el-button type="primary" :disabled="btnDisabledWithPageType" @click="handleRepairSetMealBtnClick">维修套餐</el-button>
        <el-button type="primary" :disabled="btnDisabledWithPageType" @click="handleRepairHisroryBtnClick">维修历史</el-button>
        <AjaxButton type="primary" :disabled="topBtnDisabledStatus.printBtn" :click="handlePrintStockRequistion">打印拣料单</AjaxButton>
        <el-button type="primary" :disabled="btnDisabledWithPageType || isFirstMaintenanceChecked" @click="handleRepairSuggestBtnClick">维修建议</el-button>
        <el-button type="primary" :disabled="btnDisabledWithPageType" @click="handleMonitorBtnClick">监控信息</el-button>
        <el-button type="primary" :disabled="btnDisabledWithPageType" @click="handleComplainHistoryClick">客诉历史</el-button>
        <!-- 审核结果，仅af涉及 -->
        <auditResult v-if="appId != 'beijing'" :disabled="topBtnDisabledStatus.printBtn" :roNo="roNoFormValue" />
      </ButtonArea>

      <!-- 项目配件详情 -->
      <el-tabs v-model="activeDetailInfoTab" tab-position="top">
        <el-tab-pane label="维修项目" name="维修项目">
          <FilterTable
            ref="repairLabourTable"
            columnsRef="repair_repairReception_customer_repairLabourTable"
            height="auto"
            :columns="repairLabourColumns"
            :dataSource="repairLabourTableDataSource"
            :isMemoryPagination="true"
            selectionType="single"
            :onSyncTableData="handleSyncRepairLabourTableData"
            :onRowSelectChange="handleRepairLabourTableSelect"
            :onCellChange="handleRepairLabourTableCellChange"
            :onColumnsChange="columns => (this.repairLabourColumns = columns)"
          >
            <template slot="controls">
              <el-button size="small" type="primary" icon="el-icon-plus" :disabled="btnDisabledWithPageType || isFirstMaintenanceChecked" @click="handleAddRepairLabour">新增项目</el-button>
              <el-button size="small" type="primary" icon="el-icon-plus" :disabled="btnDisabledWithPageType || isFirstMaintenanceChecked" @click="handleAddRepairPart">新增配件</el-button>
              <el-button size="small" type="danger" :disabled="btnDisabledWithPageType || isFirstMaintenanceChecked" @click="handleDeleteRepairLabour">删除</el-button>
            </template>
          </FilterTable>
        </el-tab-pane>
        <el-tab-pane label="维修材料" name="维修材料">
          <FilterTable
            ref="repairPartTable"
            columnsRef="repair_repairReception_customer_repairPartTable"
            height="auto"
            :columns="repairPartColumns"
            :dataSource="repairPartTableDataSource"
            :isMemoryPagination="true"
            :onSyncTableData="handleSyncRepairPartTableData"
            :onRowSelectChange="handleRepairPartTableSelect"
            :onCellChange="handleRepairPartTableCellChange"
            :onColumnsChange="columns => (this.repairPartColumns = columns)"
          >
            <template slot="controls">
              <el-button size="small" type="primary" icon="el-icon-plus" :disabled="btnDisabledWithPageType || isFirstMaintenanceChecked" @click="handleAddRepairPart">新增配件</el-button>
              <el-button size="small" type="danger" :disabled="btnDisabledWithPageType || isFirstMaintenanceChecked" @click="handleDeleteRepairPart">删除</el-button>
            </template>
          </FilterTable>
        </el-tab-pane>
        <el-tab-pane label="附加项目" name="附加项目">
          <FilterTable
            ref="additionItemTable"
            columnsRef="repair_repairReception_customer_additionItemTable"
            height="auto"
            :columns="additionItemColumns"
            :dataSource="additionItemTableDataSource"
            :isMemoryPagination="true"
            :onSyncTableData="handleSyncAdditionItemTableData"
            :onRowSelectChange="handleAdditionItemTableSelect"
            :onCellChange="handleAdditionItemTableCellChange"
            :onColumnsChange="columns => (this.additionItemColumns = columns)"
          >
            <template slot="controls">
              <el-button size="small" type="primary" icon="el-icon-plus" :disabled="btnDisabledWithPageType" @click="handleAddAdditionItem">新增</el-button>
              <el-button size="small" type="danger" :disabled="btnDisabledWithPageType" @click="handleDeleteAdditionItem">删除</el-button>
            </template>
          </FilterTable>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- ---------------------弹窗部分--------------------- -->
    <!-- 工单选择 -->
    <BaseDialog :visible.sync="showQueryUnderRepairOrderPanel" title="工单查询" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <queryUnderRepairOrder @close="showQueryUnderRepairOrderPanel = false" @onConfirm="handleUnderRepairOrderConfirm" />
    </BaseDialog>

    <!--  车辆选择 -->
    <BaseDialog :visible.sync="showVehicleChoicePanel" title="VIN选择" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <vehicleChoice @close="showVehicleChoicePanel = false" @onConfirm="handleVehicleChoiceConfirm" :vinOne="vinOne" />
    </BaseDialog>

    <!-- 监控信息 -->
    <Drawer :visible.sync="showMonitorMessagePanel" title="监控信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <monitorMessage :vin="carVin" :carInfo="carInfoObj" :residueSetMealCount="residueSetMealCount" @close="showMonitorMessagePanel = false" @onConfirm="handleMonitionMessageConfirm" />
    </Drawer>

    <!-- 新增维修项目 -->
    <BaseDialog :visible.sync="showAddRepairLabourPanel" title="新增维修项目" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addRepairLabour :modelId="carModelId" @close="showAddRepairLabourPanel = false" @onConfirm="handleAddRepairLabourConfirm" />
    </BaseDialog>

    <!-- 新增维修配件 -->
    <BaseDialog :visible.sync="showAddRepairPartPanel" title="新增维修配件" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addRepairPart
        :powerType="carPowerType"
        :repairLabourDict="repairLabourSelectList"
        :chargePartitionDict="sfqfDict"
        :defaultChargePartition="defaultChargePartition"
        :defaultRepairLabour="selectedRepairLabourList"
        :repairPermission="repairPermission"
        @close="showAddRepairPartPanel = false"
        @onConfirm="handleAddRepairPartConfirm"
      />
    </BaseDialog>

    <!-- 编辑维修配件 -->
    <BaseDialog :visible.sync="showEditRepairPartPanel" title="编辑维修配件" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <editRepairPart
        :repairLabourDict="repairLabourSelectList"
        :chargePartitionDict="sfqfDict"
        :editPartData="editPartData"
        :rechargeableCodes="rechargeableCodes"
        :repairPermission="repairPermission"
        @close="showEditRepairPartPanel = false"
        @onConfirm="handleEditPartConfirm"
      />
    </BaseDialog>

    <!-- 新增附加项目 -->
    <BaseDialog :visible.sync="showAddAdditionItemPanel" title="附加项目选择" width="25%" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addAdditionItem :chargePartitionDict="sfqfDict" :defaultChargePartition="defaultChargePartition" @close="showAddAdditionItemPanel = false" @onConfirm="handleAddAdditionItemConfirm" />
    </BaseDialog>

    <!-- 维修历史 -->
    <BaseDialog :visible.sync="showRepairHistoryPanel" title="维修历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <repairHistory :carInfo="carInfoObj" :vin="carVin" @close="showRepairHistoryPanel = false" />
    </BaseDialog>

    <!-- 建议维修项目 -->
    <BaseDialog :visible.sync="showRepairSuggestPanel" title="维修建议" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <repairSuggest :vin="carVin" @close="showRepairSuggestPanel = false" @onConfirm="handleRepairSuggestConfirm" />
    </BaseDialog>

    <!-- 维修套餐 -->
    <BaseDialog :visible.sync="showRepairSetMealPanel" title="维修套餐信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <repairSetMeal
        :powerType="carPowerType"
        :selectedSetMealCodeList="selectedSetMealCodeList"
        :residueSetMealCount="residueSetMealCount"
        @close="showRepairSetMealPanel = false"
        @onConfirm="handleSetMealConfirm"
      />
    </BaseDialog>

    <!-- 服务活动选择 -->
    <BaseDialog :visible.sync="showActivitySelectPanel" title="服务活动选择" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <activity :vin="carVin" :selectedAvtivityCodeList="selectedAvtivityCodeList" @close="showActivitySelectPanel = false" @onConfirm="handleActivitySelectConfirm" />
    </BaseDialog>

    <!-- 车辆送修人 -->
    <BaseDialog :visible.sync="showLinkManChoicePanel" title="车辆送修人" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <linkManChoice :vin="carVin" :ownerCode="ownerCode" @close="showLinkManChoicePanel = false" @onConfirm="handleLinkManChoiceConfirm" />
    </BaseDialog>

    <!-- 客诉历史 -->
    <BaseDialog :visible.sync="showComplainHistoryPanel" title="客诉历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <complainHistory :vin="carVin" @close="showComplainHistoryPanel = false" />
    </BaseDialog>

    <!-- 捡料单打印 -->
    <BasePrint ref="print" :data="stockRequistionPrintData" destroyOnClose template="templateRepairMaterials" />
    <!-- af全网查询车档-->
    <BaseDialog :visible.sync="showAfVe" :title="'更新/新增车辆'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerModel @setCustomerInfo="setCustomerInfo" @close="closeAndShow" :formData="this.resData" />
    </BaseDialog>
  </div>
</template>

<script>
import _ from 'lodash';
import moment from 'moment';
import { dictionary } from '@/utils/dictMixin';
import { confirmAction, notifyAction, findFormItem, findTableItem, jsonToHump, arrayObjDeWeight } from '@/utils';
import { getUserId, getAppId, getOwnerCode } from '@/assets/js/auth';
import dictCode from '@/utils/dictCode';
import { getRelationshipData } from '@/api/serviceass/batteryService/relationship';

import queryUnderRepairOrder from './queryUnderRepairOrder';
import monitorMessage from './monitorMessage';
import vehicleChoice from './vehicleChoice';
import addRepairLabour from './addRepairLabour';
import addRepairPart from './addRepairPart';
import addAdditionItem from './addAdditionItem';
import repairHistory from './repairHistory';
import repairSuggest from './repairSuggest';
import repairSetMeal from './repairSetMeal';
import activity from './activity';
import editRepairPart from './editRepairPart';
import linkManChoice from './linkManChoice';
import printRepairOrder from './printRepairOrder';
import uploadRingCheckImgs from './uploadRingCheckImgs';
import complainHistory from '../precontractArrange/complainHistory';
import auditResult from './auditResult';
import ownerModel from '@/pages/customerRepair/customerInfo/ownerVehicleManagement/tabs/ownerModel.vue';

import { searchRoleByCode } from '@/api/common/empSelect/index';
import {
  getWxlxSelect,
  getSfqfSelect,
  getBxgsSelect,
  saveRepairOrder,
  queryRepairOrderDetail,
  discardRepairOrder,
  queryVehicleWarranty,
  getUserByVinAndMobileFromJH,
  queryVehicleSpecialByVin,
  licenseForAF
} from '@/api/repair/repairReception/customer';
import { getPinpSelect, getChexSelect, queryModelBySeriesId } from '@/api/repair/repairReception/customer/brand';
import { queryUserControlDiscountMode1 } from '@/api/repair/repairReception/feesSettlement';
import { queryPrintDataByRoNoOutStockNo } from '@/api/part/partOutbound/repairMaterials/index.js';
import { getDealerUser, findUserControlStorageCode, findAllRepair, getIssuePackagesNum, getWxproductList } from '@/api/repair/common';

export default {
  name: 'repairOrder',
  components: {
    monitorMessage,
    queryUnderRepairOrder,
    vehicleChoice,
    addRepairLabour,
    addRepairPart,
    addAdditionItem,
    repairHistory,
    repairSuggest,
    repairSetMeal,
    activity,
    editRepairPart,
    linkManChoice,
    printRepairOrder,
    uploadRingCheckImgs,
    complainHistory,
    auditResult,
    ownerModel
  },
  mixins: [dictionary],
  data() {
    this.selectedRepairLabourList = []; // 选中的维修项目列表
    this.selectedRepairPartList = []; // 选中的维修配件列表
    this.selectedAdditionItemList = []; // 选中的附加项目列表
    this.deletedRepairLabourList = []; // 删除的项目列表
    this.deletedRepairPartList = []; // 删除的配件列别OA
    this.deletedAdditionItemList = []; // 删除的附加项目列表
    this.repairTypeList = []; // 全部维修类型
    this.sfqfDict = []; // 收费区分字典
    this.rechargeableCodes = ['B', 'Z']; // 需要收钱的收费区分（保险，自费）
    this.noVerifyRegisterRepairType = ['1', '11', '12', '13']; // af业务中保存时不校验是否注册的工单类型
    this.carPowerType = 60081001; // 车辆动力类型
    this.editPartData = {}; // 编辑中的配件信息
    this.discountModeList = []; // 全部优惠模式列表
    this.orderData = {}; // 工单数据
    this.repairParams = {}; // 售后参数
    this.alluserDicts = []; // 全部人员的字典项
    // 最低折扣权限
    this.discountLimt = {
      ADDITIONAL_ITEMS_DISCOUNT: 1,
      LABOUR_AMOUNT_DISCOUNT: 1,
      REPAIR_PART_DISCOUNT: 1,
      SALES_PART_DISCOUNT: 1
    };
    this.defaultRingCheckPhotoObj = {}; // 编辑查看时环检照片数据
    this.editableRepairLabourTableDataIndexs = [
      'CHARGE_PARTITION_CODE',
      'REPAIR_TYPE_CODE',
      'LABOUR_NAME',
      'LABOUR_AMOUNT',
      'ASSIGN_LABOUR_HOUR',
      'LABOUR_PRICE',
      'CONSIGN_EXTERIOR',
      'NEEDLESS_REPAIR',
      'NEEDLESS_TYPE',
      'NEEDLESS_REASON',
      'REMARK'
    ]; // 项目table可编辑字段
    this.editableRepairPartTableDataIndexs = ['REPAIR_WAY', 'CHARGE_PARTITION_CODE', 'IS_MAIN_PART', 'PART_QUANTITY', 'NEEDLESS_REPAIR', 'NEEDLESS_TYPE', 'NEEDLESS_REASON']; // 配件table可编辑字段
    this.residueSetMealCount = 0; // 套餐包剩余使用次数(套餐包为能够免费使用套餐的次数)
    this.estimateNo = ''; // 估价单号

    return {
      // 页签
      activePriceInfoTab: '自费估价信息', // 激活的费用信息tab
      activeMainOrderInfoTab: '车主车辆信息', // 激活的主要信息tab
      activeDetailInfoTab: '维修项目', // 激活的明细信息tab

      // 表单
      mainOrderInfoFormList: this.createMainOrderInfoFormList(),
      orderBaseInfoFormList: this.createOrderBaseInfoFormList(),
      selfPayPriceFormList: this.createSelfPayPriceFormList(),
      claimPayPriceFormList: this.createClaimPayPriceFormList(),
      ownerInfoFormList: this.createOwnerInfoFormList(),
      repairInfoFormList: this.createRepairInfoFormList(),
      orderRemarkFormList: this.createrderRemarkFormList(),

      // 表格
      repairLabourColumns: this.createRepairLabourColumns(),
      repairPartColumns: this.createRepairPartColumns(),
      additionItemColumns: this.createAdditionItemColumns(),

      // 弹窗
      showMonitorMessagePanel: false, // 是否显示监控信息弹窗
      showQueryUnderRepairOrderPanel: false, // 是否显示查询在修工单弹窗
      showVehicleChoicePanel: false, // 是否显示车辆选择弹窗
      showAddRepairLabourPanel: false, // 是否显示新增维修项目弹窗
      showAddRepairPartPanel: false, // 是否显示新增维修配件弹窗
      showAddAdditionItemPanel: false, // 是否显示新增附加项目弹窗
      showRepairHistoryPanel: false, // 是否显示维修历史弹窗
      showRepairSuggestPanel: false, // 是否显示维修建议弹窗
      showRepairSetMealPanel: false, // 是否显示维修套餐弹窗
      showActivitySelectPanel: false, // 是否显示服务活动选择弹窗
      showEditRepairPartPanel: false, // 是否显示编辑维修配件弹窗
      showLinkManChoicePanel: false, // 是否显示送修人选择弹窗
      showComplainHistoryPanel: false, // 是否显示客诉历史弹窗

      // 页面数据
      pageType: 'default', // 页面当前状态 default edit create create_car show
      pageIsLoading: false, // 页面是否有loading状态
      showUploadImg: false, // 是否显示上传环检照片
      uploadImgFormDisabled: true, // 上传照片表单禁用状态
      // 顶部按钮禁用状态（计算属性照顾不全所有情况，通过监听页面状态调整）
      topBtnDisabledStatus: {
        createBtn: false,
        editBtn: true,
        printBtn: true,
        saveBtn: true,
        cancenBtn: true,
        cancellationBtn: true,
        confirmBtn: true
      },
      repairLabourTableDataSource: [], // 维修项目table数据源
      repairPartTableDataSource: [], // 维修配件table数据源
      additionItemTableDataSource: [], // 附加项目table数据源
      syncRepairLabourTableDataList: [], // 同步的维修项目table数据
      syncRepairPartTableDataList: [], // 同步的维修配件table数据
      syncAdditionItemTableDataList: [], // 同步的附加项目table数据
      stockRequistionPrintData: {}, // 领料单打印数据
      appId: getAppId(),
      subRoNo: '',
      subOwnerCode: '',
      showAfVe: false,
      resData: {},
      vinOne: ''
    };
  },
  computed: {
    // 工单维修类型
    pageRepairTypeCode() {
      return findFormItem(this.orderBaseInfoFormList, 'repairTypeCode').initialValue;
    },
    // 工单维修类型对应的默认收费区分
    defaultChargePartition() {
      return this.getDefaultChargePartitionByType(this.pageRepairTypeCode);
    },
    // 维修项目下拉框(配件选择用)
    repairLabourSelectList() {
      let deweightList = arrayObjDeWeight(this.syncRepairLabourTableDataList, 'LABOUR_CODE');
      return deweightList.map(item => ({ text: item.LABOUR_NAME, value: item.LABOUR_CODE, defaultChargePartition: item.CHARGE_PARTITION_CODE }));
    },
    // 车主代码
    ownerCode() {
      return findFormItem(this.ownerInfoFormList, 'ownerNo').initialValue;
    },
    // 车辆VIN码
    carVin() {
      return findFormItem(this.ownerInfoFormList, 'vin').initialValue;
    },
    // 车辆车型
    carModelId() {
      return findFormItem(this.ownerInfoFormList, 'model').initialValue;
    },
    // 车辆信息
    carInfoObj() {
      let obj = {};
      this.ownerInfoFormList.forEach(item => {
        obj[item.fieldName] = item.initialValue;
      });
      return obj;
    },
    // 工时单价
    pageLabourPrice() {
      return findFormItem(this.orderBaseInfoFormList, 'labourPrice').initialValue;
    },
    // 根据页面状态按钮的禁用状态(基础状态)
    btnDisabledWithPageType() {
      return this.pageType !== 'create_car' && this.pageType !== 'edit';
    },
    // 编辑按钮禁用状态单独控制(同时控制打印作废及确认按钮)
    editBtnDisabled() {
      return this.pageType !== 'edit' && this.pageType !== 'show';
    },
    // 是否首保字段勾选结果
    isFirstMaintenanceChecked() {
      // return findFormItem(this.orderBaseInfoFormList, 'isFirstMaintenance').initialValue == 10041001;
      // return findFormItem(this.orderBaseInfoFormList, 'repairTypeCode').initialValue == '0';
      return false; // 厂家要求去除首保只能选择套餐的逻辑 hxj 2021-03-29
    },
    // 电话回访是否勾选
    isTraceFieldIsChecked() {
      return findFormItem(this.repairInfoFormList, 'isTrace').initialValue == 10041001;
    },
    // 已选的套餐代码（通过项目配件过滤）
    selectedSetMealCodeList() {
      return [...new Set([...this.syncRepairLabourTableDataList.map(item => item.PACKAGE_CODE), ...this.syncRepairPartTableDataList.map(item => item.PACKAGE_CODE)])];
    },
    // 已选的服务活动代码
    selectedAvtivityCodeList() {
      return [...new Set([...this.syncRepairLabourTableDataList.map(item => item.ACTIVITY_CODE), ...this.syncRepairPartTableDataList.map(item => item.ACTIVITY_CODE)])];
    },
    // 预开工时间
    estimatedTime() {
      return findFormItem(this.orderBaseInfoFormList, 'estimateBeginTime').initialValue;
    },
    // 工单号
    roNoFormValue() {
      return findFormItem(this.orderBaseInfoFormList, 'roNo').initialValue;
    },
    // 电池品牌
    batteryBrand() {
      return findFormItem(this.repairInfoFormList, 'cellBrand').initialValue;
    },
    // 维修权限
    repairPermission() {
      return localStorage.getItem(1211) ? localStorage.getItem(1211).split(',') : [];
    }
  },
  watch: {
    pageType(newVal, oldVal) {
      this.setPageFormDisabledByPageType(newVal);
    },
    // 根据首保是否勾选调整维修类型及禁用状态
    // isFirstMaintenanceChecked(newVal, oldVal) {
    //   findFormItem(this.orderBaseInfoFormList, 'repairTypeCode').initialValue = newVal ? '0' : '';
    //   findFormItem(this.orderBaseInfoFormList, 'repairTypeCode').disabled = newVal;
    //   this.clearTableData();
    // },
    // 根据是否勾选电话回访字段控制回访时间及不妨原因字段
    isTraceFieldIsChecked(newVal, oldVal) {
      findFormItem(this.repairInfoFormList, 'traceTime').disabled = !newVal;
      findFormItem(this.repairInfoFormList, 'noTraceReason').disabled = newVal;
      // findFormItem(this.repairInfoFormList, 'noTraceReason').rules = newVal ? [] : [{ required: true, message: '请输入不回访原因', trigger: 'blur' }];
      newVal && this.$refs.repairInfoForm.CLEAR_VALIDATE();
    },
    // 监听维修类型改变处理部分字段禁用状态（首保禁止修改收费区分及维修类型）
    pageRepairTypeCode(newVal, oldVal) {
      let repairTypeStatus = newVal == 0;
      findTableItem(this.repairLabourColumns, 'REPAIR_TYPE_CODE').disabled = repairTypeStatus;
      // 客户要求首保能够修改收费区分 hxj 2021-04-08 by wangbo
      // findTableItem(this.repairLabourColumns, 'CHARGE_PARTITION_CODE').disabled = repairTypeStatus;
      // findTableItem(this.repairPartColumns, 'CHARGE_PARTITION_CODE').disabled = repairTypeStatus;
      // findTableItem(this.additionItemColumns, 'CHARGE_PARTITION_CODE').disabled = repairTypeStatus;

      // 电池维修工单，电池品牌、电池类型为必填
      console.log(newVal);
      let requiredBattery = newVal == 8;
      findFormItem(this.repairInfoFormList, 'cellBrand').rules = requiredBattery ? [{ required: true, message: '电池品牌不能为空', trigger: 'change' }] : [];
      findFormItem(this.repairInfoFormList, 'cellType').rules = requiredBattery ? [{ required: true, message: '电池类型不能为空', trigger: 'change' }] : [];
      !requiredBattery && this.$refs.repairInfoForm.CLEAR_VALIDATE();
    },
    // 监听维修项目变化重新赋值维修材料中维修项目名称字典项
    repairLabourSelectList(newVal, oldVal) {
      let tableTarget = findTableItem(this.repairPartColumns, 'LABOUR_CODE');
      tableTarget.editItems = tableTarget.filterItmes = newVal;
    },
    // 预开工时间变化调整预交车时间限制
    estimatedTime(newVal, oldVal) {
      findFormItem(this.orderBaseInfoFormList, 'endTimeSupposed').minDateTime = newVal;
    },
    // 电池品牌选择后电池维修负责人及负责人电话必填
    batteryBrand(newVal, oldVal) {
      findFormItem(this.repairInfoFormList, 'cellRepairName').rules = newVal ? [{ required: true, message: '电池维修负责人不能为空', trigger: 'change' }] : [];
      findFormItem(this.repairInfoFormList, 'cellRepairPhone').rules = newVal ? [{ required: true, message: '电池维修负责人电话不能为空', trigger: 'change' }] : [];
      !newVal && this.$refs.repairInfoForm.CLEAR_VALIDATE();
    },
    // 监听路由变化 如果为估价进入且有参数的情况下赋值开单信息
    $route(to, from) {
      if (from.path == '/repair/repairReception/evaluation' && Object.keys(to.params).length) {
        this.handleCancelBtnClick();
        this.createRepairOrderByEstimateNo(to.params);
      }
    }
  },
  mounted() {
    this.initPageBaseParams(); // 初始化各种参数
    Object.keys(this.$route.params).length && this.createRepairOrderByEstimateNo(this.$route.params); // 估价单带入信息开单
    // 判断经销商类型
    if (getAppId() == 'beijing') {
      this.checkDealerType();
    }
  },
  methods: {
    /**
     * 表单，table字段布局声明
     */
    createOrderBaseInfoFormList() {
      return [
        {
          type: 'INPUT',
          label: '工单号',
          fieldName: 'roNo',
          readonly: true,
          initialValue: '',
          unitRender: () => {
            return (
              <el-button
                icon="el-icon-search"
                onClick={() => {
                  this.showQueryUnderRepairOrderPanel = true;
                }}
              />
            );
          }
        },
        {
          type: 'SELECT',
          label: '维修类型',
          fieldName: 'repairTypeCode',
          placeholder: '请选择...',
          itemList: [],
          initialValue: '',
          disabled: true,
          rules: [{ required: true, message: '请选择维修类型', trigger: 'change' }],
          change: val => {
            this.$nextTick(() => {
              this.handleRepairTypeChange(val);
            });
          }
        },
        // {
        //   type: 'CHECKBOX',
        //   label: '是否为首保',
        //   disabled: true,
        //   fieldName: 'isFirstMaintenance',
        //   initialValue: 10041002,
        //   options: {
        //     trueValue: 10041001,
        //     falseValue: 10041002
        //   }
        // },
        {
          type: 'SELECT',
          label: '是否事故维修',
          disabled: true,
          initialValue: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'DATE_TIME',
          label: '开单时间',
          disabled: true,
          initialValue: '',
          fieldName: 'roCreateDate'
        },
        {
          type: 'DATE_TIME',
          label: '预开工时间',
          fieldName: 'estimateBeginTime',
          change: val => {
            this.$nextTick(() => {
              this.calcEndTimeSupposed();
            });
          },
          disabled: true,
          initialValue: ''
        },
        {
          type: 'DATE_TIME',
          label: '预交车时间',
          fieldName: 'endTimeSupposed',
          minDateTime: '',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '工时单价',
          fieldName: 'labourPrice',
          itemList: [
            { text: 80, value: 80 }, // 油车
            { text: 100, value: 100 }, // 油电混
            { text: 260, value: 260 } // AF电车
          ],
          disabled: true,
          initialValue: 80,
          rules: [{ required: true, message: '请选择工时单价', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '保险公司',
          fieldName: 'insurationCode',
          itemList: this.createDictList(9607).map(item => ({ text: item.text, value: item.value + '' })),
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '预约单号',
          fieldName: 'bookingOrderNo',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '服务顾问',
          fieldName: 'serviceAdvisor',
          disabled: true,
          initialValue: '',
          itemList: [],
          rules: [{ required: true, message: '请选择服务顾问', trigger: 'change' }]
        }
      ];
    },
    createSelfPayPriceFormList() {
      return [
        {
          type: 'INPUT_NUMBER',
          label: '工时费',
          fieldName: 'labourAmount',
          precision: 2,
          disabled: true,
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '维修材料费',
          fieldName: 'repairPartAmount',
          precision: 2,
          disabled: true,
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '附加项目费',
          fieldName: 'addItemAmount',
          precision: 2,
          disabled: true,
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '维修金额',
          fieldName: 'totalAmount',
          precision: 2,
          disabled: true,
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '预估金额',
          fieldName: 'estimateAmount',
          precision: 2,
          disabled: true,
          initialValue: 0
        }
      ];
    },
    createClaimPayPriceFormList() {
      return [
        {
          type: 'INPUT_NUMBER',
          label: '工时费(索赔)',
          fieldName: 'labourAmountS',
          precision: 2,
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '维修材料费(索赔)',
          fieldName: 'repairPartAmountS',
          precision: 2,
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '附加项目(索赔)',
          fieldName: 'addItemAmountS',
          precision: 2,
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '维修金额(索赔)',
          fieldName: 'totalAmountS',
          precision: 2,
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '预估金额(索赔)',
          fieldName: 'estimateAmountS',
          precision: 2,
          initialValue: 0
        }
      ];
    },
    createrderRemarkFormList() {
      return [
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          disabled: true,
          initialValue: ''
        }
        // {
        //   type: 'TEXT_AREA',
        //   label: '诊断仪信息',
        //   fieldName: 'obdInfo',
        //   disabled: true,
        //   initialValue: ''
        // }
      ];
    },
    createOwnerInfoFormList() {
      return [
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          initialValue: '',
          disabled: true,
          rules: [{ required: true, message: '车牌号不能为空', trigger: 'blur' }],
          unitRender: () => {
            return (
              <el-button
                icon="el-icon-search"
                onClick={() => {
                  if (getAppId() == 'arcfox') {
                    this.showAfVe = true;
                  } else {
                    this.showVehicleChoicePanel = true;
                  }
                }}
              />
            );
          }
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          disabled: true,
          rules: [{ required: true, message: 'VIN不能为空', trigger: 'blur' }]
          // unitRender: () => {
          //   return <el-button icon="el-icon-search" />;
          // }
        },
        {
          type: 'INPUT',
          label: '车主编号',
          fieldName: 'ownerNo',
          disabled: true,
          readonly: true,
          rules: [{ required: true, message: '车主编号不能为空', trigger: 'blur' }]
          // unitRender: () => {
          //   return <el-button icon="el-icon-search" />;
          // }
        },
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'ownerName',
          disabled: true,
          rules: [{ required: true, message: '车主不能为空', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '送修人姓名',
          fieldName: 'deliverer',
          disabled: true,
          rules: [{ required: true, trigger: 'blur', message: '送修人姓名不能为空' }],
          unitRender: () => {
            return (
              <el-button
                icon="el-icon-search"
                onClick={() => {
                  this.showLinkManChoicePanel = true;
                }}
              />
            );
          }
        },
        {
          type: 'SELECT',
          label: '送修人性别',
          fieldName: 'delivererGender',
          hidden: getAppId() == 'beijing',
          disabled: true,
          itemList: this.createDictList('8012'),
          rules: [{ required: true, message: '请选择送修人性别', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '送修人手机',
          fieldName: 'delivererMobile',
          disabled: true,
          maxlength: 11,
          rules: [{ required: true, message: '送修人手机不能为空', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '车辆性质',
          fieldName: 'businessKind',
          disabled: true,
          itemList: this.createDictList('4103'),
          rules: [{ required: true, message: '车辆性质不能为空', trigger: 'change' }]
        },
        {
          type: 'DATE',
          label: '销售日期',
          fieldName: 'salesDate',
          disabled: true
          // rules: [{ required: true, message: '请填写销售日期', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'brand',
          disabled: true,
          itemList: [],
          rules: [{ required: true, message: '请选择品牌', trigger: 'change' }],
          change: this.handleBrandChange
        },
        {
          type: 'SELECT',
          label: '车系',
          fieldName: 'series',
          disabled: true,
          itemList: [],
          rules: [{ required: true, message: '请选择车系', trigger: 'change' }],
          change: this.handleSeriesChange
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'model',
          disabled: true,
          itemList: [],
          rules: [{ required: true, message: '请选择车型', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '发动机号',
          fieldName: 'engineNo',
          disabled: true
          // rules: [{ required: true, message: '请输入发动机号', pattern: /^[a-zA-Z0-9_]{0,}$/ }]
        },
        {
          type: 'INPUT',
          label: '电机号1',
          fieldName: 'motor_no1',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '电机号2',
          fieldName: 'motor_no2',
          disabled: true
        }
      ];
    },
    createRepairInfoFormList() {
      return [
        {
          type: 'INPUT_NUMBER',
          label: '进厂行驶里程',
          fieldName: 'inMileage',
          max: Infinity,
          disabled: true,
          rules: [{ required: true, message: '请输入进厂行驶里程', trigger: 'blur' }]
        },
        // {
        //   type: 'INPUT_NUMBER',
        //   label: '出厂行驶里程',
        //   fieldName: 'outMileage',
        //   disabled: true,
        //   max: Infinity
        // },
        {
          type: 'DATE',
          label: '下次保养日期',
          disabled: true,
          fieldName: 'nextMaintainDate'
        },
        {
          type: 'DATE',
          label: '上次进厂日期',
          disabled: true,
          fieldName: 'lastMaintainDate'
        },
        {
          type: 'DATE',
          label: '故障发生日',
          disabled: true,
          fieldName: 'brokeDate'
        },
        {
          type: 'INPUT_NUMBER',
          label: '下次保养里程',
          fieldName: 'nextMaintainMileage',
          disabled: true,
          max: Infinity
        },
        {
          type: 'SELECT',
          label: '进厂油量/电量',
          fieldName: 'oilRemain',
          disabled: true,
          itemList: [
            { text: '1/4', value: '1/4' },
            { text: '1/3', value: '1/3' },
            { text: '1/2', value: '1/2' },
            { text: '2/3', value: '2/3' },
            { text: '3/4', value: '3/4' },
            { text: 'FULL', value: 'FULL' }
          ]
        },
        {
          type: 'INPUT_NUMBER',
          label: '剩余续航里程',
          fieldName: 'remainingMileage',
          disabled: true,
          max: Infinity
        },
        {
          type: 'CHECKBOX',
          label: '是否电话回访',
          fieldName: 'isTrace',
          disabled: true,
          options: {
            trueValue: 10041001,
            falseValue: 10041002
          },
          initialValue: 10041002
        },
        {
          type: 'SELECT',
          label: '电话回访时间',
          fieldName: 'traceTime',
          disabled: true,
          itemList: this.createDictList(8029)
        },
        {
          type: 'INPUT',
          label: '不回访原因',
          fieldName: 'noTraceReason',
          disabled: true,
          rules: []
        },
        {
          type: 'SELECT',
          label: '电池品牌',
          fieldName: 'cellBrand',
          rules: [],
          disabled: true,
          itemList: this.createDictList(5014)
        },
        {
          type: 'SELECT',
          label: '电池类型',
          fieldName: 'cellType',
          rules: [],
          disabled: true,
          itemList: this.createDictList(5016)
        },
        {
          type: 'INPUT',
          label: '电池维修人',
          fieldName: 'cellRepairName',
          disabled: true,
          rules: []
        },
        {
          type: 'INPUT',
          label: '电池维修人员电话',
          labelWidth: '120px',
          fieldName: 'cellRepairPhone',
          disabled: true,
          rules: []
        }
      ];
    },
    createMainOrderInfoFormList() {
      return [
        {
          type: 'TEXT_AREA',
          label: '客户描述',
          fieldName: 'customerDesc',
          disabled: true,
          selfCols: 1.5,
          rows: 3,
          rules: [{ required: true, message: '请填写客户描述', trigger: 'blur' }]
        },
        {
          type: 'TEXT_AREA',
          label: '检查结果',
          fieldName: 'checkResult',
          disabled: true,
          placeholder: '请输入...',
          selfCols: 1.5,
          rows: 3,
          rules: [{ required: true, message: '请填写故障描述', trigger: 'blur' }]
        },
        {
          type: 'MULTIPLE_CHECKBOX',
          label: '',
          fieldName: 'otherRequire',
          disabled: true,
          selfCols: 3,
          initialValue: [],
          itemList: [
            { text: '带走旧件', value: 1001 },
            { text: '是否洗车', value: 1002 },
            { text: '是否充电', value: 1003 },
            { text: '是否有贵重物品', value: 1004 }
          ]
        }
      ];
    },
    createRepairLabourColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          }
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: true,
          defaultEditable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          editable: true,
          defaultEditable: true,
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '项目代码',
          dataIndex: 'LABOUR_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '项目名称',
          dataIndex: 'LABOUR_NAME',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          defaultEditable: true,
          editType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          defaultEditable: true,
          editType: 'number',
          precision: 2,
          min: 0
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'number',
          editable: true,
          defaultEditable: true,
          editType: 'number',
          precision: 2,
          min: 0
        },
        {
          title: '收费工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'number',
          // render: props => {
          //   return (
          //     <el-input-number
          //       size="mini"
          //       type="text"
          //       disabled={!(this.appId == 'beijing' && props.row.CHARGE_PARTITION_CODE == 'Z')}
          //       type="number"
          //       value={props.row.STD_LABOUR_HOUR}
          //       size="small"
          //       min={0}
          //       style="width: 100px"
          //       precision={2}
          //       controls={false}
          //       onChange={e => {}}
          //     ></el-input-number>
          //   );
          // }
          // editable: true,
          // defaultEditable: true,
          // editType: 'number',
          precision: 2
        },
        // {
        //   title: '优惠金额',
        //   dataIndex: 'DISCOUNT_AMOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   precision: 2
        // },
        // {
        //   title: '折扣率',
        //   dataIndex: 'DISCOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   editable: true,
        //   defaultEditable: true,
        //   editType: 'number',
        //   precision: 2,
        //   min: 0,
        //   max: 1
        // },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          defaultEditable: true,
          editType: 'number',
          precision: 2,
          min: 0
        },
        {
          title: '责任技师',
          dataIndex: 'TECHNICIAN',
          sorter: true,
          dictItems: [],
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          showOverflowTooltip: true
        },
        {
          title: '是否派工',
          dataIndex: 'ASSIGN_TAG',
          sorter: true,
          disabled: true,
          editable: true,
          defaultEditable: true,
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        },
        {
          title: '是否增项',
          dataIndex: 'IS_ADDITION',
          sorter: true,
          disabled: true,
          editable: true,
          defaultEditable: true,
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        },
        {
          title: '是否委外',
          dataIndex: 'CONSIGN_EXTERIOR',
          sorter: true,
          editable: true,
          defaultEditable: true,
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        },
        {
          title: '是否不修',
          dataIndex: 'NEEDLESS_REPAIR',
          sorter: true,
          editable: true,
          defaultEditable: true,
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        },
        {
          title: '不修类型',
          dataIndex: 'NEEDLESS_TYPE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1018'),
          editable: true,
          defaultEditable: true,
          editType: 'select',
          editItems: this.createDictList('1018')
        },
        {
          title: '不修原因',
          dataIndex: 'NEEDLESS_REASON',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          defaultEditable: true,
          editType: 'input'
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          width: 280,
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          defaultEditable: true,
          editType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '套餐代码',
          dataIndex: 'PACKAGE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '是否使用套餐包',
          dataIndex: 'IS_USE_SET_MEAL_PACKAGE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004),
          dictItems: this.createDictList(1004)
        }
      ];
    },
    createRepairPartColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: 150,
          render: props => {
            return (
              <el-button
                type="text"
                disabled={props.row.IS_FINISHED == 10041001 || props.row.IS_USE_SET_MEAL_PACKAGE == 10041001}
                onClick={() => {
                  this.handleEditPart(props.row);
                }}
              >
                编辑
              </el-button>
            );
          }
        },
        {
          title: '是否入账',
          dataIndex: 'IS_FINISHED',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItmes: this.createDictList(1004),
          dictItems: this.createDictList(1004)
        },
        {
          title: '维修方式',
          dataIndex: 'REPAIR_WAY',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8093'),
          editable: true,
          defaultEditable: true,
          editType: 'select',
          editRequired: true,
          editItems: this.createDictList('8093')
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: true,
          defaultEditable: true,
          editItems: [],
          editType: 'select'
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
          // editable: false,
          // defaultEditable: true,
          // editType: 'input'
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
          // editable: false,
          // defaultEditable: true,
          // editType: 'input'
        },
        {
          title: '配件销售单价',
          dataIndex: 'PART_SALES_PRICE',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
          // editable: true,
          // defaultEditable: true,
          // editType: 'number'
        },
        {
          title: '价格系数',
          dataIndex: 'PRICE_RATE',
          hidden: true,
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          editable: true,
          defaultEditable: true,
          editType: 'number',
          min: 0,
          max: 1
        },
        {
          title: '配件销售金额',
          dataIndex: 'PART_SALES_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '主要配件',
          dataIndex: 'IS_MAIN_PART',
          sorter: true,
          editable: true,
          defaultEditable: true,
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        },
        {
          title: '配件数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          defaultEditable: true,
          editType: 'number'
        },
        {
          title: '维修项目名称',
          dataIndex: 'LABOUR_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: true,
          defaultEditable: true,
          editType: 'select',
          editItems: []
        },
        // {
        //   title: '折扣率',
        //   dataIndex: 'DISCOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   editable: true,
        //   defaultEditable: true,
        //   editType: 'number',
        //   precision: 2,
        //   min: 0,
        //   max: 1
        // },
        // {
        //   title: '优惠金额',
        //   dataIndex: 'DISCOUNT_AMOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   precision: 2
        // },
        {
          title: '仓库',
          dataIndex: 'STORAGE_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          dictItems: []
        },
        // {
        //   title: '不可打折',
        //   dataIndex: 'IS_DISCOUNT',
        //   sorter: true,
        //   filter: true,
        //   disabled: true,
        //   editItems: [
        //     { text: '', trueValue: '10041001' },
        //     { text: '', falseValue: '10041002' }
        //   ]
        // },
        {
          title: '是否增项',
          dataIndex: 'IS_ADDITION',
          sorter: true,
          editable: true,
          defaultEditable: true,
          disabled: true,
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        },
        {
          title: '库位代码',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true
        },
        {
          title: '是否不修',
          dataIndex: 'NEEDLESS_REPAIR',
          sorter: true,
          editable: true,
          defaultEditable: true,
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        },
        {
          title: '不修类型',
          dataIndex: 'NEEDLESS_TYPE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1018'),
          disabled: false,
          editable: true,
          defaultEditable: true,
          editType: 'select',
          editItems: this.createDictList('1018')
        },
        {
          title: '不修原因',
          dataIndex: 'NEEDLESS_REASON',
          sorter: true,
          filter: true,
          filterType: 'input',
          disabled: false,
          editable: true,
          defaultEditable: true,
          editType: 'input'
        },
        {
          title: '流水号',
          dataIndex: 'BATCH_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          hidden: true,
          showOverflowTooltip: true
        },
        {
          title: '拣料单流水号',
          dataIndex: 'OUT_STOCK_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '套餐代码',
          dataIndex: 'PACKAGE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '是否使用套餐包',
          dataIndex: 'IS_USE_SET_MEAL_PACKAGE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004),
          dictItems: this.createDictList(1004)
        }
      ];
    },
    createAdditionItemColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 50,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'operation',
        //   render: props => {
        //     return <el-button type="text">编辑</el-button>;
        //   }
        // },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          showOverflowTooltip: true,
          editable: true,
          defaultEditable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '附加项目代码',
          dataIndex: 'ADD_ITEM_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '附加项目名称',
          dataIndex: 'ADD_ITEM_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '附加项目费',
          dataIndex: 'ADD_ITEM_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true,
          precision: 2,
          editable: true,
          defaultEditable: true,
          editType: 'number'
        },
        // {
        //   title: '折扣率',
        //   dataIndex: 'DISCOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   showOverflowTooltip: true,
        //   editable: true,
        //   defaultEditable: true,
        //   editType: 'number',
        //   precision: 2,
        //   min: 0,
        //   max: 1
        // },
        // {
        //   title: '优惠金额',
        //   dataIndex: 'DISCOUNT_AMOUNT',
        //   filter: true,
        //   filterType: 'input',
        //   sorter: true,
        //   showOverflowTooltip: true,
        //   numberFormat: true,
        //   precision: 2
        // },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          filter: true,
          filterType: 'input',
          sorter: true,
          showOverflowTooltip: true,
          numberFormat: true,
          precision: 2
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          filter: true,
          filterType: 'input',
          sorter: true,
          showOverflowTooltip: true
          // editable: true,
          // defaultEditable: true,
          // editType: 'input'
        }
      ];
    },

    /**
     * table事件
     */
    // 同步维修项目table数据
    handleSyncRepairLabourTableData(list) {
      list.forEach(item => {
        // 根据是否勾选不修开饭不修类型原因字段编辑
        if (this.$refs.repairLabourTable) {
          this.$refs.repairLabourTable.SET_CELL_DISABLED(item, 'NEEDLESS_TYPE', item.NEEDLESS_REPAIR != 10041001);
          this.$refs.repairLabourTable.SET_CELL_DISABLED(item, 'NEEDLESS_REASON', item.NEEDLESS_REPAIR != 10041001);
          // 套餐包项目禁用所有字段编辑
          if (item.IS_USE_SET_MEAL_PACKAGE == 10041001) {
            this.editableRepairLabourTableDataIndexs.forEach(item2 => {
              this.$refs.repairLabourTable.SET_CELL_DISABLED(item, item2, true);
            });
          }
        }
      });
      this.syncRepairLabourTableDataList = list;
      this.pageType == 'create_car' && this.calcEndTimeSupposed();
      console.log(this.syncRepairLabourTableDataList, 'syncRepairLabourTableDataList::');
      this.calcPayPrice();
    },
    // 同步维修配件table数据
    handleSyncRepairPartTableData(list) {
      // 可编辑字段
      list.forEach(item => {
        // 根据是否勾选不修开饭不修类型原因字段编辑
        if (this.$refs.repairPartTable) {
          this.$refs.repairPartTable.SET_CELL_DISABLED(item, 'NEEDLESS_TYPE', item.NEEDLESS_REPAIR != 10041001);
          this.$refs.repairPartTable.SET_CELL_DISABLED(item, 'NEEDLESS_REASON', item.NEEDLESS_REPAIR != 10041001);
          // 根据出库状态及是否为套餐包禁用编辑字段
          if (item.IS_FINISHED == 10041001 || item.IS_USE_SET_MEAL_PACKAGE == 10041001) {
            this.editableRepairPartTableDataIndexs.forEach(item2 => {
              this.$refs.repairPartTable.SET_CELL_DISABLED(item, item2, true);
            });
          }
          item.IS_FINISHED == 10041001 && this.$refs.repairPartTable.SET_CELL_DISABLED(item, 'LABOUR_CODE', true); // 已出库的还需要多禁用维修项目字段
        }
      });
      this.syncRepairPartTableDataList = list;
      this.calcPayPrice();
    },
    // 同步附加项目table数据
    handleSyncAdditionItemTableData(list) {
      list.forEach(item => {
        if (this.$refs.additionItemTable) {
          if (this.appId == 'beijing') {
            this.$refs.additionItemTable.SET_CELL_UNEDITABLE(item, 'ADD_ITEM_AMOUNT', false);
          } else {
            this.$refs.additionItemTable.SET_CELL_UNEDITABLE(item, 'ADD_ITEM_AMOUNT', true);
          }
        }
      });
      this.syncAdditionItemTableDataList = list;
      this.calcPayPrice();
    },
    // 维修项目行项选择变化
    handleRepairLabourTableSelect(list) {
      this.selectedRepairLabourList = list;
    },
    // 维修配件行项选择变化
    handleRepairPartTableSelect(list) {
      this.selectedRepairPartList = list;
    },
    // 附加项目行项选择变化
    handleAdditionItemTableSelect(list) {
      this.selectedAdditionItemList = list;
    },
    // 维修项目行项内容变化
    handleRepairLabourTableCellChange(data, row) {
      let dataIndex = Object.keys(data)[0].split('|')[1];
      let calcReceiveAmountDataIndexs = ['LABOUR_AMOUNT', 'LABOUR_PRICE', 'DISCOUNT', 'CHARGE_PARTITION_CODE', 'NEEDLESS_REPAIR']; // 需要重新计算实收的字段
      switch (dataIndex) {
        case 'DISCOUNT':
          if (row.DISCOUNT < this.discountLimt.LABOUR_AMOUNT_DISCOUNT) {
            notifyAction(`折扣不能小于维修项目最低折扣权限${this.discountLimt.LABOUR_AMOUNT_DISCOUNT}`, 'warning');
            row.DISCOUNT = 1;
          }
          break;
        case 'LABOUR_AMOUNT':
          row.LABOUR_PRICE = (row.STD_LABOUR_HOUR ? row.LABOUR_AMOUNT / row.STD_LABOUR_HOUR : 0).toFixed(2);
          break;
        case 'LABOUR_PRICE':
          row.LABOUR_AMOUNT = row.STD_LABOUR_HOUR * row.LABOUR_PRICE;
          break;
        case 'NEEDLESS_REPAIR':
          this.$refs.repairLabourTable.SET_CELL_DISABLED(row, 'NEEDLESS_TYPE', row.NEEDLESS_REPAIR != 10041001);
          this.$refs.repairLabourTable.SET_CELL_DISABLED(row, 'NEEDLESS_REASON', row.NEEDLESS_REPAIR != 10041001);
          row.NEEDLESS_REPAIR == 10041002 && (row.NEEDLESS_TYPE = '');
          row.NEEDLESS_REPAIR == 10041002 && (row.NEEDLESS_REASON = '');
          break;
        case 'CHARGE_PARTITION_CODE':
          // 改变维修项目的收费区分同步修改相应配件的收费区分
          let targetList = this.syncRepairPartTableDataList.filter(item => item.LABOUR_CODE == row.LABOUR_CODE);
          targetList.forEach(item => {
            item.CHARGE_PARTITION_CODE = row.CHARGE_PARTITION_CODE;
            this.calcRepairPartReceiveAmount(item); // 配件改变收费区分后需要重新计算金额
          });
          break;
      }
      if (calcReceiveAmountDataIndexs.includes(dataIndex)) {
        this.calcRepairLabourReceiveAmount(row);
        this.calcPayPrice();
      }
    },
    // 维修配件行项内容变化
    handleRepairPartTableCellChange(data, row) {
      let dataIndex = Object.keys(data)[0].split('|')[1];
      let calcReceiveAmountDataIndexs = ['CHARGE_PARTITION_CODE', 'PART_QUANTITY', 'NEEDLESS_REPAIR']; // 需要重新计算实收的字段

      switch (dataIndex) {
        case 'PART_QUANTITY':
          row.PART_SALES_AMOUNT = row.PART_SALES_PRICE * (row.PART_QUANTITY || 0);
          break;
        case 'NEEDLESS_REPAIR':
          this.$refs.repairPartTable.SET_CELL_DISABLED(row, 'NEEDLESS_TYPE', row.NEEDLESS_REPAIR != 10041001);
          this.$refs.repairPartTable.SET_CELL_DISABLED(row, 'NEEDLESS_REASON', row.NEEDLESS_REPAIR != 10041001);
          row.NEEDLESS_REPAIR == 10041002 && (row.NEEDLESS_TYPE = '');
          row.NEEDLESS_REPAIR == 10041002 && (row.NEEDLESS_REASON = '');
          break;
      }

      if (calcReceiveAmountDataIndexs.includes(dataIndex)) {
        this.calcRepairPartReceiveAmount(row);
        this.calcPayPrice();
      }
    },
    // 附加项目行项变化
    handleAdditionItemTableCellChange(data, row) {
      let dataIndex = Object.keys(data)[0].split('|')[1];
      let calcReceiveAmountDataIndexs = ['DISCOUNT', 'CHARGE_PARTITION_CODE', 'ADD_ITEM_AMOUNT']; // 需要重新计算实收的字段
      if (dataIndex == 'DISCOUNT') {
        if (row.DISCOUNT < this.discountLimt.ADDITIONAL_ITEMS_DISCOUNT) {
          notifyAction(`折扣不能小于附加项目最低折扣权限${this.discountLimt.ADDITIONAL_ITEMS_DISCOUNT}`, 'warning');
          row.DISCOUNT = 1;
        }
      }
      if (calcReceiveAmountDataIndexs.includes(dataIndex)) {
        this.calcAdditionItemReceiveAmount(row);
        this.calcPayPrice();
      }
    },

    /**
     * 初始化及字典项查询
     */
    initPageBaseParams() {
      this.setRepairPermission();
      this.getSysAppid();
      this.setDefaultLabourPriceByAppidAndCarType();
      this.queryRepairTypeDict();
      this.queryInsuranceCompany();
      this.queryServiceAdviserList();
      this.querySfqfDict();
      this.queryBrandDicts();
      this.queryDealerUser();
      this.queryDiscountModel();
      this.queryUserPermitedStorageList();
      this.queryRepairParams();
    },
    // 获取维修类型
    async queryRepairTypeDict() {
      let res = await getWxlxSelect();
      if (res.resultCode == 200) {
        this.repairTypeList = res.data;
        let repairTypeDict = res.data.map(item => ({ text: item.REPAIR_TYPE_NAME, value: item.REPAIR_TYPE_CODE + '' }));
        let laboutTableRepairType = findTableItem(this.repairLabourColumns, 'REPAIR_TYPE_CODE');
        laboutTableRepairType.editItems = laboutTableRepairType.filterItems = findFormItem(this.orderBaseInfoFormList, 'repairTypeCode').itemList = repairTypeDict;
      }
    },
    // 获取收费区分
    async querySfqfDict() {
      let res = await getSfqfSelect();
      if (res.resultCode == 200) {
        let sfqfDict = res.data.map(item => ({ text: item.CHARGE_PARTITION_NAME, value: item.CHARGE_PARTITION_CODE }));
        this.sfqfDict = sfqfDict;
        let labourChargePartition = findTableItem(this.repairLabourColumns, 'CHARGE_PARTITION_CODE');
        let partChargePartition = findTableItem(this.repairPartColumns, 'CHARGE_PARTITION_CODE');
        let addItemPartition = findTableItem(this.additionItemColumns, 'CHARGE_PARTITION_CODE');
        labourChargePartition.editItems = labourChargePartition.filterItems = partChargePartition.editItems = partChargePartition.filterItems = addItemPartition.editItems = addItemPartition.filterItems = sfqfDict;
      }
    },
    // 获取保险公司
    async queryInsuranceCompany() {
      // let res = await getBxgsSelect();
      // if (res.resultCode == 200) {
      //   console.log(res, 'hexj001');
      // }
    },
    // 获取服务顾问列表
    async queryServiceAdviserList() {
      let serviceConsultant = { role: dictCode.SERVICE_CONSULTANT };
      let res = await searchRoleByCode(serviceConsultant);
      if (res.resultCode == 200) {
        let serviceAdviserDict = res.data.map(item => ({ text: item.employeeName, value: item.userId + '' }));
        findFormItem(this.orderBaseInfoFormList, 'serviceAdvisor').itemList = serviceAdviserDict;
      }
    },
    // 查询品牌列表
    async queryBrandDicts() {
      let res = await getPinpSelect();
      if (res.resultCode == 200) {
        findFormItem(this.ownerInfoFormList, 'brand').itemList = res.data.map(item => ({ text: item.brandName, value: item.brandId + '' }));
      }
    },
    // 根据品牌及车型id初始化品牌车系下拉框
    querySeriesModelDicts(brandId, seriesId) {
      this.querySeriesDictByBrandId(brandId);
      this.queryModelDictsBySeriesId(seriesId);
    },
    // 根据品牌id查询车系
    async querySeriesDictByBrandId(brandId) {
      let res = await getChexSelect(brandId);
      if (res.resultCode == 200) {
        findFormItem(this.ownerInfoFormList, 'series').itemList = res.data.map(item => ({ text: item.seriesName, value: item.seriesId + '' }));
      }
    },
    // 根据车系id查询车型
    async queryModelDictsBySeriesId(seriesId) {
      let res = await queryModelBySeriesId({ seriesId });
      if (res.resultCode == 200) {
        findFormItem(this.ownerInfoFormList, 'model').itemList = res.data.map(item => ({ text: item.modelName, value: item.modelId + '' }));
      }
    },
    // 查询所有人员(翻译用)
    async queryDealerUser() {
      let res = await getDealerUser();
      if (res.resultCode == 200) {
        let userDicts = res.data.map(item => ({ text: item.employeeName, value: item.userId + '' }));
        this.alluserDicts = userDicts;
        let tableTargets = [findTableItem(this.repairLabourColumns, 'TECHNICIAN')];
        tableTargets.forEach(item => {
          item.dictItems = item.filterItmes = userDicts;
        });
      }
    },
    // 查询该用户全部优惠模式
    async queryDiscountModel() {
      let res = await queryUserControlDiscountMode1();
      if (res.resultCode == 200 && res.data && res.data.discountModeList) {
        this.discountModeList = res.data.discountModeList;
        this.calcMinDiscountFromDiscountMode(this.discountModeList);
      }
    },
    // 查询用户权限仓库列表
    async queryUserPermitedStorageList() {
      let res = await findUserControlStorageCode();
      if (res.resultCode == 200) {
        let storageDicts = res.data.map(item => ({ text: item.STORAGE_NAME, value: item.STORAGE_CODE }));
        let tableTarget = findTableItem(this.repairPartColumns, 'STORAGE_CODE');
        tableTarget.dictItems = tableTarget.filterItems = storageDicts;
      }
    },
    // 查询售后参数
    async queryRepairParams() {
      let res = await findAllRepair();
      if (res.resultCode == 200) {
        this.repairParams = res.data;
        this.initOtherRequire(this.repairParams); // 初始化工单信息tab中勾选的checkbox默认值
      }
    },
    // 获取appid区分北汽和AF业务
    getSysAppid() {
      this.showUploadImg = !(getAppId() == 'beijing');
      if (!this.showUploadImg) {
        // beijing业务去除服务包相关字段
        this.repairLabourColumns.pop();
        this.repairPartColumns.pop();
      }
      // this.showUploadImg = true;
    },
    // 根据appid及车辆动力类型设置默认工时单价
    setDefaultLabourPriceByAppidAndCarType() {
      let labourPrice = 80;
      if (getAppId() == 'beijing') {
        labourPrice = this.carPowerType == 60081001 ? 80 : 100;
      } else {
        labourPrice = 260;
      }
      findFormItem(this.orderBaseInfoFormList, 'labourPrice').initialValue = labourPrice;
      findFormItem(this.orderBaseInfoFormList, 'labourPrice').itemList = [{ text: labourPrice, value: labourPrice }];
    },
    // 设置维修权限
    setRepairPermission() {
      console.log(this.repairPermission, '维修权限');

      // 是否能够修改工时单价
      if (!this.repairPermission.includes('12111007')) {
        findTableItem(this.repairLabourColumns, 'LABOUR_AMOUNT').disabled = true;
        findTableItem(this.repairLabourColumns, 'LABOUR_PRICE').disabled = true;
      }
    },

    /**
     * 弹窗相关
     */
    // 点击监控信息按钮
    handleMonitorBtnClick() {
      this.showMonitorMessagePanel = true;
    },
    // 点击维修历史
    handleRepairHisroryBtnClick() {
      this.showRepairHistoryPanel = true;
    },
    // 点击客诉历史
    handleComplainHistoryClick() {
      this.showComplainHistoryPanel = true;
    },
    // 点击维修建议
    handleRepairSuggestBtnClick() {
      this.showRepairSuggestPanel = true;
    },
    // 点击维修套餐
    handleRepairSetMealBtnClick() {
      this.showRepairSetMealPanel = true;
    },
    // 点击服务活动
    handleActivityBtnClick() {
      this.showActivitySelectPanel = true;
    },
    // 点击新增项目
    handleAddRepairLabour() {
      if (!this.pageRepairTypeCode) return notifyAction('请先选择维修类型', 'warning');
      if (!this.carModelId) return notifyAction('请先维护车辆车型', 'warning');
      this.showAddRepairLabourPanel = true;
    },
    // 点击新增维修配件
    handleAddRepairPart() {
      if (!this.pageRepairTypeCode) return notifyAction('请先选择维修类型', 'warning');
      if (!this.selectedRepairLabourList.length) return notifyAction('请选择配件对应的维修项目', 'warning');
      this.showAddRepairPartPanel = true;
    },
    // 点击新增附加项目
    handleAddAdditionItem() {
      if (!this.pageRepairTypeCode) return notifyAction('请先选择维修类型', 'warning');
      this.showAddAdditionItemPanel = true;
    },
    // 维修配件点击编辑
    handleEditPart(row) {
      this.editPartData = row;
      this.showEditRepairPartPanel = true;
    },
    // 监控信息点击确定
    async handleMonitionMessageConfirm({ active, foward }) {
      // 活动带入页面
      if (active.length) {
        console.log('服务活动带回');
        //如果是arcfox将工单类型改成售后
        if (getAppId() == 'arcfox') {
          console.log('触发');
          this.orderBaseInfoFormList.find(x => x.fieldName == 'repairTypeCode').initialValue = '12';
          // this.pageRepairTypeCode = 12;
        }
        this.insertRepairLabourToTable(active[0].labourList || []);
        this.insertRepairPartToTable(active[0].partList || []);
      }
      // 预约单带入页面
      if (foward.length) {
        let bookingOrderNo = findFormItem(this.orderBaseInfoFormList, 'bookingOrderNo').initialValue;
        if (bookingOrderNo == foward[0].BOOKING_ORDER_NO) return notifyAction('预约单不可重复带入', 'warning');
        if (bookingOrderNo && bookingOrderNo != foward[0].BOOKING_ORDER_NO) {
          try {
            await confirmAction('带入新预约单将清空当前维修项目及配件，是否继续');
            this.repairLabourTableDataSource = [];
            this.repairPartTableDataSource = [];
          } catch (err) {
            console.log(err);
            return;
          }
        }
        this.$nextTick(() => {
          this.subRoNo = foward[0].SUB_RO_NO;
          this.subOwnerCode = foward[0].SUB_OWNER_CODE;
          this.insertRepairLabourToTable(foward[0].labour || []);
          this.insertRepairPartToTable(foward[0].part || []);
          findFormItem(this.orderBaseInfoFormList, 'bookingOrderNo').initialValue = foward[0].BOOKING_ORDER_NO;
        });
      }
    },
    // 工单选择点击确定
    handleUnderRepairOrderConfirm(e) {
      this.qwuerOrderDetailByRoNo(e.RO_NO);
    },
    // 车辆选择带出事件
    async handleVehicleChoiceConfirm(e) {
      this.ownerInfoFormList.forEach(item => {
        item.initialValue = e[item.fieldName];
      });
      this.repairInfoFormList.forEach(item => {
        item.initialValue = e[item.fieldName];
        // item.fieldName == 'outMileage' && (item.min = e.inMileage || 0); // 出厂行驶里程不能小于进厂里程 出厂里程去除 hxj 20210318
      });
      this.querySeriesModelDicts(e.brand, e.series); // 初始化车系车型下拉框
      this.queryVehicleWarrantyByVin(e.vin, e.ownerName); // 查询该车辆是否终身质保
      this.queryVehicleSpecialByVin(e.vin, e.ownerName); // 查询该车辆是否终身质保
      this.carPowerType = e.powerType; // 车辆动力类型单独存放(用于配件添加的选择)
      this.setDefaultLabourPriceByAppidAndCarType(); // 设置默认工时单价
      this.showVehicleChoicePanel = false;
      findFormItem(this.orderBaseInfoFormList, 'estimateBeginTime').initialValue = moment().format('YYYY-MM-DD HH:mm:ss'); // 赋值初始化预开工时间
      try {
        await this.queryIssuePackageNum(e.vin); // 查询车辆剩余服务包次数 uat不需要 暂时注释 hxj 2020-03-12
      } catch (err) {
        console.log(err, '查询车辆剩余维修包次数失败');
      }
      this.pageType = 'create_car';
      this.$nextTick(() => {
        this.handleMonitorBtnClick();
      });
    },
    // 送修人选择带出事件
    handleLinkManChoiceConfirm(e) {
      findFormItem(this.ownerInfoFormList, 'deliverer').initialValue = e.ownerName;
      // findFormItem(this.ownerInfoFormList, 'delivererGender').initialValue = e.gender; 性别去除 hxj 20210318
      findFormItem(this.ownerInfoFormList, 'delivererMobile').initialValue = e.mobile;
      this.showLinkManChoicePanel = false;
    },
    // 维修项目选择点击确定
    handleAddRepairLabourConfirm(list) {
      this.insertRepairLabourToTable(list);
    },
    // 维修配件选择点击确定
    handleAddRepairPartConfirm(e) {
      this.insertRepairPartToTable(e);
    },
    // 附加项目选择点击确定
    handleAddAdditionItemConfirm(e) {
      this.insertAdditionItemToTable(e);
    },
    // 维修建议选择点击确定
    handleRepairSuggestConfirm(e) {
      e.labourList.length && this.insertRepairLabourToTable(e.labourList);
      e.partList.length && this.insertRepairPartToTable(e.partList);
    },
    // 维修套餐带回
    handleSetMealConfirm(e) {
      e.labourList.length && this.insertRepairLabourToTable(e.labourList);
      e.partList.length && this.insertRepairPartToTable(e.partList);
    },
    // 服务活动带回
    handleActivitySelectConfirm(e) {
      this.insertRepairLabourToTable(e.labourList || []);
      this.insertRepairPartToTable(e.partList || []);
    },
    // 编辑维修配件点击确定
    handleEditPartConfirm(e) {
      let targetRow = this.syncRepairPartTableDataList.find(item => item._uid == e._uid);
      Object.assign(targetRow, e);
      this.calcPayPrice();
      this.showEditRepairPartPanel = false;
    },

    /**
     * 页面函数
     */
    // 点击新建
    handleCreateNewOrderBtnClick() {
      this.pageType = 'create';
      // 设置默认数据
      let servicFormItem = findFormItem(this.orderBaseInfoFormList, 'serviceAdvisor');
      servicFormItem.itemList.find(item => item.value == getUserId()) && (servicFormItem.initialValue = getUserId());
      findFormItem(this.orderBaseInfoFormList, 'roCreateDate').initialValue = moment().format('YYYY-MM-DD HH:mm:ss');
      this.initOtherRequire(this.repairParams); // 初始化工单信息tab中勾选的checkbox默认值
      this.$nextTick(() => {
        if (getAppId() == 'arcfox') {
          this.showAfVe = true;
        } else {
          this.showVehicleChoicePanel = true;
        }
      });
    },
    // 点击取消
    handleCancelBtnClick() {
      this.clearPageData();
      this.activePriceInfoTab = '自费估价信息';
      this.activeMainOrderInfoTab = '车主车辆信息';
      this.activeDetailInfoTab = '维修项目';
      this.pageType = 'default';
      this.subRoNo = '';
      this.subOwnerCode = '';
    },
    // 点击编辑
    handleEditBtnClick() {
      this.pageType = 'edit';
    },
    // 清空页面数据
    clearPageData() {
      this.$refs.orderBaseInfoForm.RESET_FORM();
      this.$refs.selfPayPriceForm.RESET_FORM();
      this.$refs.claimPayPriceForm.RESET_FORM();
      this.$refs.ownerInfoForm.RESET_FORM();
      this.$refs.repairInfoForm.RESET_FORM();
      this.$refs.mainOrderInfoForm.RESET_FORM();
      this.$refs.orderRemarkForm.RESET_FORM();
      this.showUploadImg && this.$refs.uploadRingCheckImgs.clearFormData();

      this.estimateNo = null;

      this.repairLabourTableDataSource = [];
      this.repairPartTableDataSource = [];
      this.additionItemTableDataSource = [];
      this.selectedRepairLabourList = [];
      this.selectedRepairPartList = [];
      this.selectedAdditionItemList = [];
      this.deletedRepairLabourList = [];
      this.deletedRepairPartList = [];
      this.deletedAdditionItemList = [];
    },
    // 根据页面类型设置页面表单按钮禁用状态
    setPageFormDisabledByPageType(pageType) {
      this.setTopBtnAllDisabled(); // 先禁用所有按钮，然后根据页面状态单独调整
      this.topBtnDisabledStatus.cancenBtn = false;

      switch (pageType) {
        case 'create':
          findFormItem(this.orderBaseInfoFormList, 'serviceAdvisor').disabled = false;
          findFormItem(this.orderBaseInfoFormList, 'roNo').disabled = true;
          findFormItem(this.ownerInfoFormList, 'license').disabled = false;
          this.uploadImgFormDisabled = true;
          this.topBtnDisabledStatus.saveBtn = false;
          break;
        case 'create_car':
          // 先全部放开后禁用部分字段
          this.setFormAllFieldDisabled(this.orderBaseInfoFormList, false);
          this.setFormAllFieldDisabled(this.ownerInfoFormList, false);
          this.setFormAllFieldDisabled(this.mainOrderInfoFormList, false);
          this.setFormAllFieldDisabled(this.repairInfoFormList, false);
          this.setFormAllFieldDisabled(this.orderRemarkFormList, false);

          this.setFormFieldDisabled(this.orderBaseInfoFormList, ['roNo', 'roCreateDate', 'bookingOrderNo'], true);
          this.setFormFieldDisabled(this.ownerInfoFormList, ['license', 'vin', 'ownerNo', 'ownerName', 'salesDate'], true);
          this.setFormFieldDisabled(this.repairInfoFormList, ['traceTime', 'nextMaintainDate', 'nextMaintainMileage', 'lastMaintainDate'], true);
          this.carPowerType == 60081001 && this.setFormFieldDisabled(this.repairInfoFormList, ['remainingMileage'], true); //剩余续航单独处理
          findFormItem(this.repairInfoFormList, 'isTrace').initialValue = 10041002;
          this.uploadImgFormDisabled = false;
          this.topBtnDisabledStatus.saveBtn = false;
          break;
        case 'show':
          this.setFormAllFieldDisabled(this.orderBaseInfoFormList, true);
          this.setFormAllFieldDisabled(this.ownerInfoFormList, true);
          this.setFormAllFieldDisabled(this.mainOrderInfoFormList, true);
          this.setFormAllFieldDisabled(this.repairInfoFormList, true);
          this.setFormAllFieldDisabled(this.orderRemarkFormList, true);
          this.uploadImgFormDisabled = true;
          this.topBtnDisabledStatus.editBtn = false;
          this.topBtnDisabledStatus.printBtn = false;
          this.topBtnDisabledStatus.confirmBtn = false;
          break;
        case 'edit':
          this.setFormAllFieldDisabled(this.orderBaseInfoFormList, false);
          this.setFormAllFieldDisabled(this.ownerInfoFormList, false);
          this.setFormAllFieldDisabled(this.mainOrderInfoFormList, false);
          this.setFormAllFieldDisabled(this.repairInfoFormList, false);
          this.setFormAllFieldDisabled(this.orderRemarkFormList, false);

          this.setFormFieldDisabled(this.orderBaseInfoFormList, ['roNo', 'roCreateDate', 'bookingOrderNo'], true);
          this.setFormFieldDisabled(this.ownerInfoFormList, ['license', 'vin', 'ownerNo', 'ownerName', 'salesDate'], true);
          this.setFormFieldDisabled(this.repairInfoFormList, ['nextMaintainDate', 'nextMaintainMileage', 'lastMaintainDate'], true);
          this.carPowerType == 60081001 && this.setFormFieldDisabled(this.repairInfoFormList, ['remainingMileage'], true); // 剩余续航单独处理
          findFormItem(this.repairInfoFormList, 'traceTime').disabled = !this.isTraceFieldIsChecked; // 电话回访时间及不回访原因单独处理
          findFormItem(this.repairInfoFormList, 'noTraceReason').disabled = this.isTraceFieldIsChecked;
          this.uploadImgFormDisabled = false;
          this.topBtnDisabledStatus.printBtn = false;
          this.topBtnDisabledStatus.saveBtn = false;
          this.topBtnDisabledStatus.cancellationBtn = false;
          this.topBtnDisabledStatus.confirmBtn = false;
          break;
        case 'default':
          this.setFormAllFieldDisabled(this.orderBaseInfoFormList, true);
          this.setFormAllFieldDisabled(this.ownerInfoFormList, true);
          this.setFormAllFieldDisabled(this.mainOrderInfoFormList, true);
          this.setFormAllFieldDisabled(this.repairInfoFormList, true);
          this.setFormAllFieldDisabled(this.orderRemarkFormList, true);
          findFormItem(this.orderBaseInfoFormList, 'roNo').disabled = false;
          this.uploadImgFormDisabled = true;
          this.topBtnDisabledStatus.cancenBtn = true; // 取消按钮仅在默认状态禁用
          this.topBtnDisabledStatus.createBtn = false;
          break;
      }
    },
    // 设置顶部按钮全禁用
    setTopBtnAllDisabled() {
      Object.keys(this.topBtnDisabledStatus).forEach(item => {
        this.topBtnDisabledStatus[item] = true;
      });
    },
    // 设置全部表单禁用状态
    setFormAllFieldDisabled(formList, status) {
      formList.forEach(item => {
        item.disabled = status;
      });
    },
    // 批量设置表单字段禁用状态
    setFormFieldDisabled(formList, fields, status) {
      fields.forEach(item => {
        findFormItem(formList, item).disabled = status;
      });
    },
    // 过滤优惠模式中各项优惠最小值
    calcMinDiscountFromDiscountMode(modeList) {
      let obj = {
        REPAIR_PART_DISCOUNT: 1,
        LABOUR_AMOUNT_DISCOUNT: 1,
        ADDITIONAL_ITEMS_DISCOUNT: 1,
        SALES_PART_DISCOUNT: 1
      };
      let calcObj = modeList.reduce((t, v) => {
        t.REPAIR_PART_DISCOUNT = v.REPAIR_PART_DISCOUNT < t.REPAIR_PART_DISCOUNT ? v.REPAIR_PART_DISCOUNT : t.REPAIR_PART_DISCOUNT;
        t.LABOUR_AMOUNT_DISCOUNT = v.LABOUR_AMOUNT_DISCOUNT < t.LABOUR_AMOUNT_DISCOUNT ? v.LABOUR_AMOUNT_DISCOUNT : t.LABOUR_AMOUNT_DISCOUNT;
        t.ADDITIONAL_ITEMS_DISCOUNT = v.ADDITIONAL_ITEMS_DISCOUNT < t.ADDITIONAL_ITEMS_DISCOUNT ? v.ADDITIONAL_ITEMS_DISCOUNT : t.ADDITIONAL_ITEMS_DISCOUNT;
        t.SALES_PART_DISCOUNT = v.SALES_PART_DISCOUNT < t.SALES_PART_DISCOUNT ? v.SALES_PART_DISCOUNT : t.SALES_PART_DISCOUNT;
        return t;
      }, obj);
      this.discountLimt = calcObj;
      console.log('折扣权限:', this.discountLimt);
    },
    // 大写字段名转驼峰
    arrayObjToHump(data) {
      let copy = _.cloneDeep(data);
      jsonToHump(copy);
      return copy;
    },
    // 赋值工单信息tab中的checkbox默认勾选值
    initOtherRequire(repairParams) {
      let arr = [];
      repairParams[8019] == '1' && arr.push(1001); // 带走旧件
      repairParams[1067] == '1' && arr.push(1002); // 是否洗车
      repairParams[1070] == '1' && arr.push(1003); // 是否充电
      repairParams[1071] == '1' && arr.push(1004); // 是否贵重物品
      findFormItem(this.mainOrderInfoFormList, 'otherRequire').initialValue = arr;
    },
    // 根据vin查询车辆剩余优惠包次数
    async queryIssuePackageNum(vin) {
      let res = await getIssuePackagesNum({ vin });
      if (res.resultCode == 200) {
        this.residueSetMealCount = res.data.num;
      }
    },
    // 根据维修类型code获取默认收费区分
    getDefaultChargePartitionByType(type) {
      let repairTypeRow = this.repairTypeList.find(item => item.REPAIR_TYPE_CODE == type);
      return repairTypeRow ? repairTypeRow.CHARGE_PARTITION_CODE : 'Z';
    },
    // 工单打印成功事件
    handleOrderPirntSuccess() {
      this.orderData.firstPrintTime = this.orderData.firstPrintTime || moment().format('YYYY-MM-DD HH:mm:ss');
    },
    // 根据vin查询车辆是否为终身质保
    async queryVehicleWarrantyByVin(vin, ownerName) {
      let res = await queryVehicleWarranty({ vin, ownerName });
      if (res.resultCode == 200) {
        let array = res.data.split(',');
        if (array[0] == '1') {
          let type = array[1] ? array[1] : '';
          type = this.createDictText(type, 8888);
          console.log('type', type);
          notifyAction('此车辆为' + type + '终身质保车辆！', 'warning');
        }
        // res.data == 1 && notifyAction('此车辆为终身质保车辆！', 'warning');
      }
    },
    // 根据vin查询车辆特殊质保
    async queryVehicleSpecialByVin(vin, ownerName) {
      let res = await queryVehicleSpecialByVin({ vin, ownerName });
      if (res.resultCode == 200 && res.data != '') {
        notifyAction(res.data, 'warning');
        // res.data == 1 && notifyAction('此车辆为终身质保车辆！', 'warning');
      }
    },
    // 新增维修项目插入页面
    insertRepairLabourToTable(labourList) {
      // 校验想要插入的列表是否有重复项目，维修项目不能重复添加
      let repetitionLabourCodes = labourList.filter(item => !!this.syncRepairLabourTableDataList.find(item2 => item2.LABOUR_CODE == item.LABOUR_CODE)).map(item => item.LABOUR_CODE);
      repetitionLabourCodes.length && notifyAction(`项目代码为${repetitionLabourCodes.join(',')}的维修项目已存在，不能重复添加。`, 'warning');
      let insertLabourList = labourList.filter(item => !this.syncRepairLabourTableDataList.find(item2 => item2.LABOUR_CODE == item.LABOUR_CODE));

      insertLabourList.forEach(item => {
        item.REPAIR_TYPE_CODE = item.REPAIR_TYPE_CODE || this.pageRepairTypeCode;
        item.LABOUR_PRICE = item.LABOUR_PRICE || this.pageLabourPrice || 0;
        item.CHARGE_PARTITION_CODE = item.CHARGE_PARTITION_CODE || this.getDefaultChargePartitionByType(item.REPAIR_TYPE_CODE);
        item.DISCOUNT = item.DISCOUNT || 1;
        item.LABOUR_AMOUNT = item.LABOUR_AMOUNT || item.LABOUR_PRICE * item.STD_LABOUR_HOUR;
        item.CONSIGN_EXTERIOR = this.pageRepairTypeCode == 8 ? 10041001 : 10041002;
        // 增项逻辑调整北京为按照打印 AF为编辑即为增项
        if (getAppId() == 'beijing') {
          item.IS_ADDITION = this.pageType == 'edit' && this.orderData.firstPrintTime ? 10041001 : 10041002;
        } else {
          item.IS_ADDITION = this.pageType == 'edit' ? 10041001 : 10041002;
        }
        this.calcRepairLabourReceiveAmount(item);
      });

      this.$refs.repairLabourTable.EXECUTE_INSERT(insertLabourList);
      notifyAction('维修项目插入成功', 'success');
    },
    // 新增维修配件插入页面
    insertRepairPartToTable(partList) {
      partList.forEach(item => {
        item.REPAIR_TYPE_CODE = item.REPAIR_TYPE_CODE || this.pageRepairTypeCode;
        item.CHARGE_PARTITION_CODE = item.CHARGE_PARTITION_CODE || this.getDefaultChargePartitionByType(item.REPAIR_TYPE_CODE);
        item.PART_QUANTITY = item.PART_QUANTITY || 1;
        item.PART_SALES_AMOUNT = item.PART_SALES_PRICE * item.PART_QUANTITY;
        item.PRICE_RATE = item.PRICE_RATE || 1;
        item.PRICE_TYPE = item.PRICE_TYPE || 82481001;
        item.REPAIR_WAY = 80931002;
        item.DISCOUNT = 1;
        item.IS_FINISHED = 10041002;
        // 增项逻辑调整北京为按照打印 AF为编辑即为增项
        if (getAppId() == 'beijing') {
          item.IS_ADDITION = this.pageType == 'edit' && this.orderData.firstPrintTime ? 10041001 : 10041002;
        } else {
          item.IS_ADDITION = this.pageType == 'edit' ? 10041001 : 10041002;
        }
        this.calcRepairPartReceiveAmount(item);
      });

      this.$refs.repairPartTable.EXECUTE_INSERT(partList);
      notifyAction('维修配件插入成功', 'success');
    },
    // 新增附加项目插入页面
    insertAdditionItemToTable(addItem) {
      addItem.DISCOUNT = 1;
      // 增项逻辑调整北京为按照打印 AF为编辑即为增项
      if (getAppId() == 'beijing') {
        addItem.IS_ADDITION = this.pageType == 'edit' && this.orderData.firstPrintTime ? 10041001 : 10041002;
      } else {
        addItem.IS_ADDITION = this.pageType == 'edit' ? 10041001 : 10041002;
      }
      this.calcAdditionItemReceiveAmount(addItem);

      this.$refs.additionItemTable.EXECUTE_INSERT([addItem]);
      notifyAction('附加项目插入成功', 'success');
    },
    // 根据收费区分及折扣重新计算维修项目实收及折扣金额
    async calcRepairLabourReceiveAmount(row) {
      if (this.appId == 'beijing') {
        console.log(row, 'rowSSSSS::');
        if (row.CHARGE_PARTITION_CODE != 'Z' || row.IS_USE_SET_MEAL_PACKAGE == 10041001) {
          // this.$refs.repairLabourTable.SET_CELL_UNEDITABLE(row, 'STD_LABOUR_HOUR', true);
          // let res = await getWxproductList({ labourCode: row.LABOUR_CODE });
          // if (res.resultCode == 200) {
          //   row.STD_LABOUR_HOUR = res.data.rows[0].STD_LABOUR_HOUR;
          // }
        } else {
          this.$refs.repairLabourTable.SET_CELL_UNEDITABLE(row, 'STD_LABOUR_HOUR', true);
        }
        row.LABOUR_AMOUNT = (row.STD_LABOUR_HOUR * row.LABOUR_PRICE).toFixed(2);
      } else {
        this.$refs.repairLabourTable.SET_CELL_UNEDITABLE(row, 'STD_LABOUR_HOUR', true);
      }
      row.RECEIVE_AMOUNT = row.NEEDLESS_REPAIR == 10041001 ? 0 : this.rechargeableCodes.includes(row.CHARGE_PARTITION_CODE) ? row.LABOUR_AMOUNT * row.DISCOUNT : 0;
      row.DISCOUNT_AMOUNT = row.NEEDLESS_REPAIR == 10041001 ? 0 : this.rechargeableCodes.includes(row.CHARGE_PARTITION_CODE) ? row.LABOUR_AMOUNT - row.LABOUR_AMOUNT * row.DISCOUNT : 0;
      console.log(row, 'rowcalcRepairLabourReceiveAmount::');
    },
    // 根据收费区分重新计算维修配件实收
    calcRepairPartReceiveAmount(row) {
      row.RECEIVE_AMOUNT = row.NEEDLESS_REPAIR == 10041001 ? 0 : this.rechargeableCodes.includes(row.CHARGE_PARTITION_CODE) ? row.PART_SALES_AMOUNT * row.DISCOUNT : 0;
    },
    // 根据收费区分及折扣率重新计算附加项目实收
    async calcAdditionItemReceiveAmount(row) {
      if (this.appId == 'beijing') {
        console.log(1111111111);
        this.$refs.additionItemTable.SET_CELL_UNEDITABLE(row, 'ADD_ITEM_AMOUNT', false);
      } else {
        this.$refs.additionItemTable.SET_CELL_UNEDITABLE(row, 'ADD_ITEM_AMOUNT', true);
      }
      row.RECEIVE_AMOUNT = this.rechargeableCodes.includes(row.CHARGE_PARTITION_CODE) ? row.ADD_ITEM_AMOUNT * row.DISCOUNT : 0;
      row.DISCOUNT_AMOUNT = this.rechargeableCodes.includes(row.CHARGE_PARTITION_CODE) ? row.ADD_ITEM_AMOUNT - row.ADD_ITEM_AMOUNT * row.DISCOUNT : 0;
    },
    // 页面维修类型改变
    handleRepairTypeChange(e) {
      // 切换为首保类型时需要清空选择的项目及配件
      // e == 0 && this.clearTableData(); // 此逻辑去除 hxj 2021-04-09 by wangbo
      // e == 0 && (findFormItem(this.orderBaseInfoFormList, 'isFirstMaintenance').initialValue = 10041001);

      // 切换为电池维修时是否委外为默认勾选否则取消
      this.syncRepairLabourTableDataList.forEach(item => {
        item.CONSIGN_EXTERIOR = e == 8 ? 10041001 : 10041002;
      });

      this.$nextTick(() => {
        // 重新赋值项目配件收费区分及维修类型并重新计算（套餐包的配件项目不参与修改）
        this.syncRepairLabourTableDataList.forEach(item => {
          if (item.IS_USE_SET_MEAL_PACKAGE != 10041001) {
            item.REPAIR_TYPE_CODE = e;
            item.CHARGE_PARTITION_CODE = this.defaultChargePartition;
          }
          this.calcRepairLabourReceiveAmount(item);
        });
        this.syncRepairPartTableDataList.forEach(item => {
          if (item.IS_USE_SET_MEAL_PACKAGE != 10041001) {
            item.CHARGE_PARTITION_CODE = this.defaultChargePartition;
          }
          this.calcRepairPartReceiveAmount(item);
        });
        this.syncAdditionItemTableDataList.forEach(item => {
          item.CHARGE_PARTITION_CODE = this.defaultChargePartition;
          this.calcAdditionItemReceiveAmount(item);
        });
        this.calcPayPrice();
      });
    },
    // 清空table数据
    clearTableData() {
      this.repairLabourTableDataSource = [];
      this.repairPartTableDataSource = [];
      this.additionItemTableDataSource = [];
    },
    // 维修项目删除点击
    handleDeleteRepairLabour() {
      if (!this.selectedRepairLabourList.length) return notifyAction('请选择需要删除的维修项目', 'warning');
      // 过滤使用套餐包项目的套餐代码
      let setMealPackageCodes = [...new Set(this.selectedRepairLabourList.filter(item => item.IS_USE_SET_MEAL_PACKAGE == 10041001).map(item => item.PACKAGE_CODE))];

      confirmAction(`此操作将删除选中的维修项目及相关配件，${setMealPackageCodes.length ? '套餐包套餐也将整体删除，' : ''}是否继续`, 'warning')
        .then(() => {
          let deleteLabours = setMealPackageCodes.length ? this.syncRepairLabourTableDataList.filter(item => setMealPackageCodes.includes(item.PACKAGE_CODE)) : this.selectedRepairLabourList; // 要删除的项目
          let labourCodes = deleteLabours.map(item => item.LABOUR_CODE);
          let relevantParts = this.syncRepairPartTableDataList.filter(item => labourCodes.includes(item.LABOUR_CODE) || setMealPackageCodes.includes(item.PACKAGE_CODE)); // 项目相关配件,或者同套餐包的配件

          // 将删除的数据储存到删除的列表中
          deleteLabours.forEach(item => {
            item.ITEM_ID && this.deletedRepairLabourList.push(item);
          });
          relevantParts.forEach(item => {
            item.ITEM_ID && this.deletedRepairPartList.push(item);
          });

          this.$refs.repairLabourTable.EXECUTE_DELETE(deleteLabours);
          relevantParts.length && this.$refs.repairPartTable.EXECUTE_DELETE(relevantParts);
        })
        .catch(err => {});
    },
    // 维修配件点击删除
    handleDeleteRepairPart() {
      if (!this.selectedRepairPartList.length) return notifyAction('请选择需要删除的维修配件', 'warning');
      // 过滤出套餐包配件的套餐代码
      let setMealPackageCodes = [...new Set(this.selectedRepairPartList.filter(item => item.IS_USE_SET_MEAL_PACKAGE == 10041001).map(item => item.PACKAGE_CODE))];

      confirmAction(`此操作将删除选中的维修配件，${setMealPackageCodes.length ? '套餐包套餐也将整体删除，' : ''}是否继续`, 'warning')
        .then(() => {
          let deleteParts = setMealPackageCodes.length ? this.syncRepairPartTableDataList.filter(item => setMealPackageCodes.includes(item.PACKAGE_CODE)) : this.selectedRepairPartList; // 要删除的项目
          let relevantLabour = this.syncRepairLabourTableDataList.filter(item => setMealPackageCodes.includes(item.PACKAGE_CODE)); // 套餐包关联的项目

          // 将删除的数据储存到删除的列表中
          relevantLabour.forEach(item => {
            item.ITEM_ID && this.deletedRepairLabourList.push(item);
          });
          deleteParts.forEach(item => {
            item.ITEM_ID && this.deletedRepairPartList.push(item);
          });

          relevantLabour.length && this.$refs.repairLabourTable.EXECUTE_DELETE(relevantLabour);
          this.$refs.repairPartTable.EXECUTE_DELETE(deleteParts);
        })
        .catch(err => {});
    },
    // 附加项目点击删除
    handleDeleteAdditionItem() {
      if (!this.selectedAdditionItemList.length) return notifyAction('请选择需要删除的附加项目', 'warning');
      confirmAction('此操作将删除选中的附加项目，是否继续', 'warning')
        .then(() => {
          this.selectedAdditionItemList.forEach(item => {
            item.ITEM_ID && this.deletedAdditionItemList.push(item);
          });
          this.$refs.additionItemTable.EXECUTE_DELETE(this.selectedAdditionItemList);
        })
        .catch(err => {});
    },
    async checkDealerType() {
      console.log('查询联合中心');
      let res = await getRelationshipData({dycode:getOwnerCode()});
      if (res.resultCode == 200) {
        let companyList = res.data.records.map(x => x.dycode);
        if (companyList.indexOf(getOwnerCode()) == -1) {
          this.repairInfoFormList.find(x => x.fieldName == 'cellType').itemList = this.createDictList(5016, 50161001);
        }
      }
    },
    // 品牌选择变化
    handleBrandChange(val) {
      this.$nextTick(async () => {
        let serIesFormItem = findFormItem(this.ownerInfoFormList, 'series');
        let modelFormItem = findFormItem(this.ownerInfoFormList, 'model');

        serIesFormItem.initialValue = '';
        modelFormItem.initialValue = '';
        modelFormItem.itemList = [];

        val && this.querySeriesDictByBrandId(val);
      });
    },
    // 车系选择变化
    handleSeriesChange(val) {
      this.$nextTick(async () => {
        let modelFormItem = findFormItem(this.ownerInfoFormList, 'model');
        modelFormItem.initialValue = '';
        this.queryModelDictsBySeriesId(val);
      });
    },
    // 计算预交车时间
    calcEndTimeSupposed() {
      let startTime = findFormItem(this.orderBaseInfoFormList, 'estimateBeginTime').initialValue;
      let totalRepairMinute =
        this.syncRepairLabourTableDataList.reduce((item, next) => {
          item += next.STD_LABOUR_HOUR;
          return item;
        }, 0) * 60;
      let residueRepairMinute = totalRepairMinute; // 剩余维修时间
      let spanDays = 0; // 维修跨越的天数

      // 9301 参数中的上班时间 9302 参数中的下班时间
      let todaySurplusMinutes = 0; // 当日离下班剩余时间(分钟)
      let oneDayStandardMinutes = 480; // 一天中的标准工作时间(分钟) 默认8小时

      // 校验上下班时间
      if (this.repairParams[9302] < this.repairParams[9301]) {
        confirmAction('营业下班时间小于上班时间，请于维修基础参数功能中调整，否则将导致预交车时间不准确。', 'warning');
      } else {
        todaySurplusMinutes = moment(startTime.split(' ')[0] + ` ${this.repairParams[9302]}:00`).diff(moment(startTime), 'minute');
        oneDayStandardMinutes = moment(startTime.split(' ')[0] + ` ${this.repairParams[9302]}:00`).diff(moment(startTime.split(' ')[0] + ` ${this.repairParams[9301]}:00`), 'minute');
      }

      // 当天不能完工的情况
      if (totalRepairMinute > todaySurplusMinutes) {
        residueRepairMinute -= todaySurplusMinutes;
        while (residueRepairMinute > 0) {
          residueRepairMinute -= oneDayStandardMinutes;
          spanDays++;
        }
        residueRepairMinute += oneDayStandardMinutes; // 将计算时减去的时间补回来方便计算结束时间
        startTime = startTime.split(' ')[0] + ` ${this.repairParams[9301]}:00`;
      }

      // 计算结束时间，先增加跨越的天数，后补足时间
      let endTime = moment(startTime)
        .add(spanDays, 'days')
        .add(residueRepairMinute, 'minutes')
        .format('YYYY-MM-DD HH:mm:ss');

      findFormItem(this.orderBaseInfoFormList, 'endTimeSupposed').initialValue = endTime;
    },
    // 工单作废 brd中规定没有项目和配件的工单才能作废
    async handleDiscardRepairOrderClick() {
      if (this.syncRepairLabourTableDataList.length || this.syncRepairPartTableDataList.length) return notifyAction('工单存在项目或配件，请删除保存后再进行作废', 'warning');
      confirmAction('此操作将作废此工单且不可找回，是否继续', 'warning').then(async () => {
        let res = await discardRepairOrder({ roNo: findFormItem(this.orderBaseInfoFormList, 'roNo').initialValue });
        if (res.resultCode == 200) {
          notifyAction('工单作废成功', 'success');
          this.handleCancelBtnClick();
        }
      });
    },
    // 计算页面预估金额
    calcPayPrice() {
      let selfPayObj = { labourAmount: 0, repairPartAmount: 0, addItemAmount: 0, totalAmount: 0, estimateAmount: 0 };
      let claimPayObj = { labourAmountS: 0, repairPartAmountS: 0, addItemAmountS: 0, totalAmountS: 0, estimateAmountS: 0 };

      // 维修项目金额
      this.syncRepairLabourTableDataList.forEach(item => {
        item.CHARGE_PARTITION_CODE == 'S' ? (claimPayObj.labourAmountS += +item.LABOUR_AMOUNT) : (selfPayObj.labourAmount += +item.RECEIVE_AMOUNT);
      });
      // 维修配件金额
      this.syncRepairPartTableDataList.forEach(item => {
        item.CHARGE_PARTITION_CODE == 'S' ? (claimPayObj.repairPartAmountS += +item.PART_SALES_AMOUNT) : (selfPayObj.repairPartAmount += +item.RECEIVE_AMOUNT);
      });
      // 附加项目金额
      this.syncAdditionItemTableDataList.forEach(item => {
        item.CHARGE_PARTITION_CODE == 'S' ? (claimPayObj.addItemAmountS += +item.ADD_ITEM_AMOUNT) : (selfPayObj.addItemAmount += +item.RECEIVE_AMOUNT);
      });

      selfPayObj.totalAmount = selfPayObj.estimateAmount = selfPayObj.labourAmount + selfPayObj.repairPartAmount + selfPayObj.addItemAmount;
      claimPayObj.totalAmountS = claimPayObj.estimateAmountS = claimPayObj.labourAmountS + claimPayObj.repairPartAmountS + claimPayObj.addItemAmountS;

      Object.keys(selfPayObj).forEach(item => {
        findFormItem(this.selfPayPriceFormList, item).initialValue = selfPayObj[item];
      });
      Object.keys(claimPayObj).forEach(item => {
        findFormItem(this.claimPayPriceFormList, item).initialValue = claimPayObj[item];
      });
    },
    // 点击打印领料单
    async handlePrintStockRequistion() {
      if (!this.selectedRepairPartList.length) {
        notifyAction('请选择一条已出库的配件信息', 'warning');
        return false;
      }

      let outStockNo = ''; // 取第一条领料单号
      this.selectedRepairPartList.forEach(item => {
        !outStockNo && item.OUT_STOCK_NO && (outStockNo = item.OUT_STOCK_NO);
      });
      if (!outStockNo) {
        notifyAction('所选配件未出库，请先出库在打印领料单', 'warning');
        return false;
      }

      await this.queryPrintDataByRoNoOutStockNo(this.roNoFormValue, outStockNo);
    },
    // 领料单打印函数
    async queryPrintDataByRoNoOutStockNo(roNo, outStockNo) {
      let res = await queryPrintDataByRoNoOutStockNo({ roNo, outStockNo });
      if (res.resultCode == 200) {
        // 翻译服务顾问和技师
        if (res.data) {
          let serviceAdvisor = this.alluserDicts.find(item => res.data.SERVICE_ADVISOR == item.value);
          let chiefTechnician = this.alluserDicts.find(item => res.data.CHIEF_TECHNICIAN == item.value);
          res.data.SERVICE_ADVISOR = serviceAdvisor ? serviceAdvisor.text : res.data.SERVICE_ADVISOR;
          res.data.CHIEF_TECHNICIAN = chiefTechnician ? chiefTechnician.text : res.data.CHIEF_TECHNICIAN;
          let sender = this.alluserDicts.find(item => res.data.SENDER == item.value);
          let receiver = this.alluserDicts.find(item => res.data.RECEIVER == item.value);
          res.data.SENDER = sender ? sender.text : res.data.SENDER;
          res.data.RECEIVER = receiver ? receiver.text : res.data.RECEIVER;
        }
        // 翻译发料人和领料人
        if (res.data && res.data.items.length) {
          res.data.items.forEach(x => {
            let sender = this.alluserDicts.find(item => x.SENDER == item.value);
            let receiver = this.alluserDicts.find(item => x.RECEIVER == item.value);
            x.SENDER = sender ? sender.text : x.SENDER;
            x.RECEIVER = receiver ? receiver.text : x.RECEIVER;
          });
        }
        this.stockRequistionPrintData = res.data;
        this.$refs.print.EXCUTE_PRINT();
      }
    },

    // 开单保存前校验拼接数据
    async orderPreSaveCheck() {
      // 表单校验
      let orderBaseInfoFormData = await this.$refs.orderBaseInfoForm.GET_FORM_DATA();
      let ownerFormData = await this.$refs.ownerInfoForm.GET_FORM_DATA();
      let repairInfoFormData = await this.$refs.repairInfoForm.GET_FORM_DATA();
      let mainOrderInfoFormmData = await this.$refs.mainOrderInfoForm.GET_FORM_DATA();
      let orderRemarkFormData = await this.$refs.orderRemarkForm.GET_FORM_DATA();
      let selfPayPriceFormData = await this.$refs.selfPayPriceForm.GET_FORM_DATA();
      let ringCheckImgs = this.showUploadImg ? await this.$refs.uploadRingCheckImgs.getFormData() : [false, {}];
      if (orderBaseInfoFormData[0] || ownerFormData[0] || repairInfoFormData[0] || mainOrderInfoFormmData[0] || orderRemarkFormData[0] || selfPayPriceFormData[0] || ringCheckImgs[0])
        return Promise.reject();

      // 表单数据合法性校验
      if (orderBaseInfoFormData[1].estimateBeginTime && orderBaseInfoFormData[1].endTimeSupposed) {
        if (new Date(orderBaseInfoFormData[1].estimateBeginTime) > new Date(orderBaseInfoFormData[1].endTimeSupposed)) {
          notifyAction('预交车时间不能小于预开工时间，请重新调整', 'warning');
          return Promise.reject();
        }
      }
      // table数据合法性校验
      if (!this.syncRepairLabourTableDataList.length) {
        notifyAction('请至少添加一项维修项目', 'warning');
        return Promise.reject();
      }

      // 校验配件
      let noEmptyLabourCodeflag = true; // 维修配件必须关联某个项目校验
      let zeroCountPartFlag = true; // 是否有数量为0的配件
      let noChargePartitionCodeFlag = true; // 收费区分是否为空
      this.syncRepairPartTableDataList.forEach(item => {
        !item.LABOUR_CODE && (noEmptyLabourCodeflag = false);
        !+item.PART_QUANTITY && (zeroCountPartFlag = false);
        !item.CHARGE_PARTITION_CODE && (noChargePartitionCodeFlag = false);
      });
      if (!noEmptyLabourCodeflag) {
        notifyAction('维修配件的对应维修项目不能为空，请维护', 'warning');
        return Promise.reject();
      }
      if (!zeroCountPartFlag) {
        notifyAction('维修配件数量不能为0，请重新维护', 'warning');
        return Promise.reject();
      }
      if (!noChargePartitionCodeFlag) {
        notifyAction('配件收费区分不能为空，请维护', 'warning');
        return Promise.reject();
      }

      // 校验项目
      let labourNoChargePartitionCodeFlag = true; // 收费区分是否为空
      this.syncRepairLabourTableDataList.forEach(item => {
        !item.CHARGE_PARTITION_CODE && (labourNoChargePartitionCodeFlag = false);
      });
      if (!labourNoChargePartitionCodeFlag) {
        notifyAction('维修项目收费区分不能为空，请维护', 'warning');
        return Promise.reject();
      }

      let accordClaimLabourList = this.syncRepairLabourTableDataList.filter(item => item.DATA_SOURCES == 10451001 && item.CHARGE_PARTITION_CODE == 'S');
      if (accordClaimLabourList.length) {
        notifyAction(`项目代码：${accordClaimLabourList.map(item => item.LABOUR_CODE).join(',')}，为店端自建项目，收费区分不能为索赔，请调整`, 'warning');
        return Promise.reject();
      }

      // 拼接接环检照片
      let photoMap = {};
      Object.keys(ringCheckImgs[1]).forEach(item => {
        photoMap[item] = ringCheckImgs[1][item].length ? ringCheckImgs[1][item][0] : null;
      });

      // AF业务校验环检照片数量(外观必传7，车内必传2，底盘必传2，其他选传)
      if (this.showUploadImg) {
        let countObj = { appearanceCounts: 0, trimCounts: 0, chassisCounts: 0 };
        let appearanceKeys = ['LEFT_FRONT', 'RIGHT_FRONT', 'LEFT_REAR', 'RIGHT_REAR', 'LEFT_SIDE', 'RIGHT_SIDE', 'TOP', 'OTHER_REPLENISH1', 'OTHER_REPLENISH2'];
        let trimKeys = ['TRIM1', 'TRIM2', 'TRIM3', 'TRIM4'];
        let chassisKeys = ['UNDERPAN1', 'UNDERPAN2', 'UNDERPAN3', 'UNDERPAN4'];
        appearanceKeys.forEach(item => photoMap[item] && countObj.appearanceCounts++);
        trimKeys.forEach(item => photoMap[item] && countObj.trimCounts++);
        chassisKeys.forEach(item => photoMap[item] && countObj.chassisCounts++);
        if (countObj.appearanceCounts < 7 || countObj.trimCounts < 2 || countObj.chassisCounts < 2) {
          let str = '车辆环检要求：';
          countObj.appearanceCounts < 7 && (str += '外观照片不能小于7张 ');
          countObj.trimCounts < 2 && (str += '内饰照片不能小于2张 ');
          countObj.chassisCounts < 2 && (str += '底盘照片不能小于2张 ');
          str += '请补充对应环检照片';
          notifyAction(str, 'warning');
          return Promise.reject();
        }
      }

      // 比较实收是否变化添加变更标识
      this.syncRepairLabourTableDataList.forEach(item => {
        item.ITEM_ID && item.RECEIVE_AMOUNT_COPY != item.RECEIVE_AMOUNT && (item.IS_CHANGE_RECEIVE_AMOUNT = 10041001);
      });
      this.syncRepairPartTableDataList.forEach(item => {
        item.ITEM_ID && item.RECEIVE_AMOUNT_COPY != item.RECEIVE_AMOUNT && (item.IS_CHANGE_RECEIVE_AMOUNT = 10041001);
      });
      this.syncAdditionItemTableDataList.forEach(item => {
        item.ITEM_ID && item.RECEIVE_AMOUNT_COPY != item.RECEIVE_AMOUNT && (item.IS_CHANGE_RECEIVE_AMOUNT = 10041001);
      });

      // 手动处理部分数据
      let otherRequire = mainOrderInfoFormmData[1].otherRequire;
      mainOrderInfoFormmData[1].isTakePartOld = otherRequire.includes(1001) ? 10041001 : 10041002; // 带走旧件
      mainOrderInfoFormmData[1].isWash = otherRequire.includes(1002) ? 10041001 : 10041002; // 是否洗车
      mainOrderInfoFormmData[1].isCharge = otherRequire.includes(1003) ? 10041001 : 10041002; // 是否充电
      mainOrderInfoFormmData[1].isHaveValuables = otherRequire.includes(1004) ? 10041001 : 10041002; // 是否有贵重物品
      // let numberDataIndexs = ['outMileage', 'remainingMileage']; // 出厂里程要求去除 hxj 20210318
      let numberDataIndexs = ['remainingMileage']; // 出厂里程/剩余续航里程number组件 无值默认0 保存为垃圾数据 手动处理为null
      numberDataIndexs.forEach(item => {
        repairInfoFormData[1][item] = repairInfoFormData[1][item] == 0 ? null : repairInfoFormData[1][item];
      });

      return {
        activityTraceTag: this.selectedAvtivityCodeList.join(','),
        ...orderBaseInfoFormData[1],
        ...ownerFormData[1],
        ...repairInfoFormData[1],
        ...mainOrderInfoFormmData[1],
        ...orderRemarkFormData[1],
        ...selfPayPriceFormData[1],
        powerType: this.carPowerType,
        estimateNo: this.estimateNo,
        dms_table: this.arrayObjToHump(this.syncRepairLabourTableDataList), // 维修项目
        dms_part: this.arrayObjToHump(this.syncRepairPartTableDataList), // 维修配件
        dms_subjoinItem: this.arrayObjToHump(this.syncAdditionItemTableDataList), // 附加项目
        delLabourList: this.arrayObjToHump(this.deletedRepairLabourList), // 删除的维修项目
        delPartList: this.arrayObjToHump(this.deletedRepairPartList), // 删除的维修材料
        delAddLabourList: this.arrayObjToHump(this.deletedAdditionItemList), // 删除的附加项目
        photoMap // 环检照片
      };
    },
    // 根据工单号查询工单明细
    async qwuerOrderDetailByRoNo(roNo) {
      this.showQueryUnderRepairOrderPanel = false;
      this.pageIsLoading = true;
      try {
        let res = await queryRepairOrderDetail({ roNo });
        if (res.resultCode == 200) {
          this.orderData = res.data;
          await this.insertRepairOrderData(res.data); // 将数据插入页面

          this.pageType = 'show';
        }
      } catch (err) {
        console.log(err, '获取工单详情失败');
      } finally {
        this.pageIsLoading = false;
      }
    },
    // 估价单导出工单
    async createRepairOrderByEstimateNo(data) {
      console.log(data, '估价单带入');
      await this.insertRepairOrderData(data);
      this.estimateNo = data.estimateNo;
      this.pageType = 'create_car';
      this.$nextTick(() => {
        this.calcEndTimeSupposed();
      });
    },
    // 工单数据插入页面
    async insertRepairOrderData(data) {
      this.querySeriesModelDicts(data.brand, data.series); // 初始化车系车型下拉框
      let formTargets = [...this.mainOrderInfoFormList, ...this.orderBaseInfoFormList, ...this.ownerInfoFormList, ...this.repairInfoFormList, ...this.orderRemarkFormList];
      formTargets.forEach(item => {
        item.initialValue = data[item.fieldName];
      });

      // 拷贝实收金额，用于判断是否修改
      data.labourList.forEach(item => {
        item.RECEIVE_AMOUNT_COPY = item.RECEIVE_AMOUNT;
      });
      data.partList.forEach(item => {
        item.RECEIVE_AMOUNT_COPY = item.RECEIVE_AMOUNT;
      });
      data.addLabourlist.forEach(item => {
        item.RECEIVE_AMOUNT_COPY = item.RECEIVE_AMOUNT;
      });

      this.repairLabourTableDataSource = data.labourList;
      this.repairPartTableDataSource = data.partList;
      this.additionItemTableDataSource = data.addLabourlist;

      // 单独处理部分页面数据字段
      this.carPowerType = data.powerType;
      this.setDefaultLabourPriceByAppidAndCarType(); // 设置默认工时单价
      // if (data.repairTypeCode == '0') findFormItem(this.orderBaseInfoFormList, 'isFirstMaintenance').initialValue = 10041001;
      this.defaultRingCheckPhotoObj = data.PHOTO_MAP || {};
      this.showUploadImg && Object.keys(this.defaultRingCheckPhotoObj).length && this.$refs.uploadRingCheckImgs.initDefaultData(this.defaultRingCheckPhotoObj); // 渲染环检照片数据
      let otherInfoArr = [];
      data.isTakePartOld == 10041001 && otherInfoArr.push(1001);
      data.isWash == 10041001 && otherInfoArr.push(1002);
      data.isCharge == 10041001 && otherInfoArr.push(1003);
      data.isHaveValuables == 10041001 && otherInfoArr.push(1004);
      findFormItem(this.mainOrderInfoFormList, 'otherRequire').initialValue = otherInfoArr;
      try {
        await this.queryIssuePackageNum(data.vin); // 查询车辆剩余服务包次数 uat不需要 暂时注释 hxj 2020-03-12
      } catch (err) {
        console.log(err, '获取车辆剩余服务包次数失败');
      }
    },
    // af查询车档点击确定
    async setCustomerInfo(row) {
      let res = await licenseForAF({ vinOne: row.vin, appId: getAppId() });
      if (res.resultCode == 200) {
        this.showAfVe = false;
        this.showVehicleChoicePanel = true;
        this.vinOne = row.vin;
      }
    },
    closeAndShow() {
      this.showAfVe = false;
      this.showVehicleChoicePanel = true;
    },
    // 点击保存
    async handleSaveRepairOrder() {
      try {
        let saveData = await this.orderPreSaveCheck();
        // AF保存前校验是否注册app， 其中PDI 售前 售后 其他不做校验
        if (getAppId() != 'beijing' && !this.noVerifyRegisterRepairType.includes(saveData.repairTypeCode)) {
          let res = await getUserByVinAndMobileFromJH({ vin: saveData.vin, mobile: saveData.delivererMobile });
          if (res.resultCode == 200 && res.data != 1) {
            //  1的时候是符合条件0不符合
            return notifyAction('此车辆或送修人手机未在APP注册，请先前往APP注册', 'warning');
          } else if (res.resultCode != 200) {
            return notifyAction('校验app注册接口调用失败,请重试', 'warning');
          }
        }
        if (getAppId() == 'beijing') {
          saveData.subOwnerCode = this.subOwnerCode;
          saveData.subRoNo = this.subRoNo;
        }
        let res = await saveRepairOrder(saveData);
        if (res.resultCode == 200) {
          findFormItem(this.orderBaseInfoFormList, 'roNo').initialValue = res.data;
          this.qwuerOrderDetailByRoNo(res.data);
          notifyAction('保存成功', 'success');
          this.pageType = 'show';
        }
      } catch (err) {
        console.log(err, '工单保存前校验未通过');
      }
    }
  }
};
</script>

<style lang="less">
.mainWrap {
  position: relative;
  padding-bottom: @modulePadding;
  .left {
    position: absolute;
    left: 0;
    width: 280px;
    // border: 1px solid @borderColor;
    border-radius: @borderRadius;
    box-shadow: @boxShadow;
    padding: @modulePadding;
    // padding-left: 0;
    background: #fff;
  }
  .right {
    margin-left: 310px;
    background: #fff;
    // border: 1px solid @borderColor;
    border-radius: @borderRadius;
    box-shadow: @boxShadow;
    padding: @modulePadding;
    .vownerPanelFrom {
      .el-col-8:nth-child(19) {
        margin-bottom: 0 !important;
      }
    }
  }
}
</style>
